licailing 3 yıl önce
ebeveyn
işleme
5081282f20

+ 1 - 1
src/main/java/com/izouma/nineth/domain/Asset.java

@@ -189,7 +189,7 @@ public class Asset extends BaseEntity {
                 .owner(user.getNickname())
                 .ownerId(user.getId())
                 .ownerAvatar(user.getAvatar())
-                .type(CollectionType.DEFAULT)
+                .type(collection.getType())
                 .holdDays(collection.getHoldDays())
                 .build();
     }

+ 19 - 0
src/main/java/com/izouma/nineth/domain/ShowCollection.java

@@ -1,8 +1,27 @@
 package com.izouma.nineth.domain;
 
+import io.swagger.annotations.ApiModel;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
 import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.hibernate.annotations.Where;
+
+import javax.persistence.Entity;
+import javax.persistence.Index;
+import javax.persistence.Table;
 
 @Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@Entity
+@Where(clause = "del = 0")
+@Table(indexes = {
+        @Index(columnList = "showroomId"),
+        @Index(columnList = "collectionId")
+})
+@ApiModel("展厅藏品")
 public class ShowCollection extends BaseEntity {
 
     private Long showroomId;

+ 19 - 4
src/main/java/com/izouma/nineth/domain/Showroom.java

@@ -1,11 +1,29 @@
 package com.izouma.nineth.domain;
 
+import io.swagger.annotations.ApiModel;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
 import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.hibernate.annotations.Where;
 
+import javax.persistence.Entity;
+import javax.persistence.Index;
+import javax.persistence.Table;
 import javax.persistence.Transient;
 import java.util.List;
 
 @Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@Entity
+@Table(indexes = {
+        @Index(columnList = "userId"),
+        @Index(columnList = "assetId")
+})
+@Where(clause = "del = 0")
+@ApiModel("展厅")
 public class Showroom extends BaseEntity {
     private Long userId;
 
@@ -15,7 +33,7 @@ public class Showroom extends BaseEntity {
 
     private String introduction;
 
-    private int like;
+    private int likes;
 
     private int share;
 
@@ -23,7 +41,4 @@ public class Showroom extends BaseEntity {
 
     @Transient
     private List<ShowCollection> collections;
-//    @Convert(converter = LongArrayConverter.class)
-//    @Column(columnDefinition = "TEXT")
-//    private List<Long> collectionId;
 }

+ 2 - 1
src/main/java/com/izouma/nineth/enums/CollectionType.java

@@ -3,7 +3,8 @@ package com.izouma.nineth.enums;
 public enum CollectionType {
     DEFAULT("默认"),
     BLIND_BOX("盲盒"),
-    AUCTION("拍卖");
+    AUCTION("拍卖"),
+    SHOWROOM("展厅");
 
     private final String description;
 

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

@@ -0,0 +1,16 @@
+package com.izouma.nineth.repo;
+
+import com.izouma.nineth.domain.ShowCollection;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+
+import javax.transaction.Transactional;
+
+public interface ShowCollectionRepo extends JpaRepository<ShowCollection, Long>, JpaSpecificationExecutor<ShowCollection> {
+    @Query("update ShowCollection t set t.del = true where t.id = ?1")
+    @Modifying
+    @Transactional
+    void softDelete(Long id);
+}

+ 26 - 0
src/main/java/com/izouma/nineth/repo/ShowroomRepo.java

@@ -0,0 +1,26 @@
+package com.izouma.nineth.repo;
+
+import com.izouma.nineth.domain.Showroom;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+
+import javax.transaction.Transactional;
+import java.util.Optional;
+
+public interface ShowroomRepo extends JpaRepository<Showroom, Long>, JpaSpecificationExecutor<Showroom> {
+    @Query("update Showroom t set t.del = true where t.id = ?1")
+    @Modifying
+    @Transactional
+    void softDelete(Long id);
+
+    @Query("update Showroom t set t.likes = t.likes + ?2 where t.id = ?1")
+    @Modifying
+    @Transactional
+    void addLike(Long id, int num);
+
+    Optional<Showroom> findByUserIdAndAssetId(Long userId, Long assetId);
+
+    Optional<Showroom> findByAssetId(Long assetId);
+}

+ 10 - 0
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -52,6 +52,8 @@ public class AssetService {
     private SysConfigService   sysConfigService;
     private RocketMQTemplate   rocketMQTemplate;
     private GeneralProperties  generalProperties;
+    private ShowroomRepo       showroomRepo;
+
 
     public Page<Asset> all(PageQuery pageQuery) {
         Page<Asset> all = assetRepo.findAll(JpaUtils.toSpecification(pageQuery, Asset.class), JpaUtils.toPageRequest(pageQuery));
@@ -188,6 +190,14 @@ public class AssetService {
         if (asset.isPublicShow()) {
             cancelPublic(asset);
         }
+
+        //寄售中的展厅需要先删除展厅
+        if (CollectionType.SHOWROOM.equals(asset.getType())) {
+            if (showroomRepo.findByAssetId(id).isPresent()) {
+                throw new BusinessException("请先删除展厅");
+            }
+        }
+
         Collection collection = Collection.builder()
                 .name(asset.getName())
                 .pic(asset.getPic())

+ 4 - 2
src/main/java/com/izouma/nineth/service/NewsLikeService.java

@@ -4,6 +4,7 @@ import com.izouma.nineth.domain.NewsLike;
 import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.repo.NewsLikeRepo;
 import com.izouma.nineth.repo.NewsRepo;
+import com.izouma.nineth.repo.ShowroomRepo;
 import com.izouma.nineth.utils.JpaUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Page;
@@ -17,6 +18,7 @@ public class NewsLikeService {
 
     private NewsLikeRepo newsLikeRepo;
     private NewsRepo     newsRepo;
+    private ShowroomRepo showroomRepo;
 
     public Page<NewsLike> all(PageQuery pageQuery) {
         return newsLikeRepo.findAll(JpaUtils.toSpecification(pageQuery, NewsLike.class), JpaUtils.toPageRequest(pageQuery));
@@ -47,14 +49,14 @@ public class NewsLikeService {
                 .userId(userId)
                 .showroomId(roomId)
                 .build());
-//        newsRepo.addLike(newsId, 1);
+        showroomRepo.addLike(roomId, 1);
     }
 
     public void unlikeRoom(Long userId, Long roomId) {
         List<NewsLike> list = newsLikeRepo.findByUserIdAndShowroomId(userId, roomId);
         if (!list.isEmpty()) {
             newsLikeRepo.deleteAll(list);
-//            newsRepo.addLike(newsId, -list.size());
+            showroomRepo.addLike(roomId, -list.size());
         }
     }
 }

+ 20 - 0
src/main/java/com/izouma/nineth/service/ShowCollectionService.java

@@ -0,0 +1,20 @@
+package com.izouma.nineth.service;
+
+import com.izouma.nineth.domain.ShowCollection;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.repo.ShowCollectionRepo;
+import com.izouma.nineth.utils.JpaUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.stereotype.Service;
+
+@Service
+@AllArgsConstructor
+public class ShowCollectionService {
+
+    private ShowCollectionRepo showCollectionRepo;
+
+    public Page<ShowCollection> all(PageQuery pageQuery) {
+        return showCollectionRepo.findAll(JpaUtils.toSpecification(pageQuery, ShowCollection.class), JpaUtils.toPageRequest(pageQuery));
+    }
+}

+ 71 - 0
src/main/java/com/izouma/nineth/service/ShowroomService.java

@@ -0,0 +1,71 @@
+package com.izouma.nineth.service;
+
+import com.izouma.nineth.domain.Asset;
+import com.izouma.nineth.domain.Collection;
+import com.izouma.nineth.domain.ShowCollection;
+import com.izouma.nineth.domain.Showroom;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.enums.AssetStatus;
+import com.izouma.nineth.enums.CollectionType;
+import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.AssetRepo;
+import com.izouma.nineth.repo.CollectionRepo;
+import com.izouma.nineth.repo.ShowroomRepo;
+import com.izouma.nineth.utils.JpaUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+@AllArgsConstructor
+public class ShowroomService {
+
+    private ShowroomRepo   showroomRepo;
+    private AssetRepo      assetRepo;
+    private CollectionRepo collectionRepo;
+
+    public Page<Showroom> all(PageQuery pageQuery) {
+        return showroomRepo.findAll(JpaUtils.toSpecification(pageQuery, Showroom.class), JpaUtils.toPageRequest(pageQuery));
+    }
+
+    /*
+    做盲盒? 加字段?
+     */
+    public void create(Long userId, Showroom showroom) {
+        Asset asset = assetRepo.findById(showroom.getAssetId()).orElseThrow(new BusinessException("资产不存在"));
+        if (!userId.equals(asset.getUserId())) {
+            throw new BusinessException("该资产不属于你");
+        }
+        if (!CollectionType.SHOWROOM.equals(asset.getType())) {
+            throw new BusinessException("不是展厅藏品");
+        }
+        if (AssetStatus.NORMAL.equals(asset.getStatus())) {
+            throw new BusinessException("该状态不可创建展厅");
+        }
+        if (asset.isConsignment()) {
+            throw new BusinessException("寄售中不可以创建");
+        }
+
+        if (showroomRepo.findByAssetId(showroom.getAssetId()).isPresent()) {
+            throw new BusinessException("已创建过展厅");
+        }
+
+        List<ShowCollection> showCollections = showroom.getCollections();
+        List<Long> collectionIds = showCollections.stream()
+                .map(ShowCollection::getCollectionId)
+                .collect(Collectors.toList());
+
+        List<Collection> collections = collectionRepo.findAllByIdIn(collectionIds);
+        collections.forEach(collection -> {
+            if (!userId.equals(collection.getOwnerId())) {
+                throw new BusinessException("该藏品不属于你");
+            }
+        });
+
+        showroomRepo.save(showroom);
+
+    }
+}

+ 60 - 0
src/main/java/com/izouma/nineth/web/ShowCollectionController.java

@@ -0,0 +1,60 @@
+package com.izouma.nineth.web;
+import com.izouma.nineth.domain.ShowCollection;
+import com.izouma.nineth.service.ShowCollectionService;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.ShowCollectionRepo;
+import com.izouma.nineth.utils.ObjUtils;
+import com.izouma.nineth.utils.excel.ExcelUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+@RestController
+@RequestMapping("/showCollection")
+@AllArgsConstructor
+public class ShowCollectionController extends BaseController {
+    private ShowCollectionService showCollectionService;
+    private ShowCollectionRepo showCollectionRepo;
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/save")
+    public ShowCollection save(@RequestBody ShowCollection record) {
+        if (record.getId() != null) {
+            ShowCollection orig = showCollectionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            ObjUtils.merge(orig, record);
+            return showCollectionRepo.save(orig);
+        }
+        return showCollectionRepo.save(record);
+    }
+
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/all")
+    public Page<ShowCollection> all(@RequestBody PageQuery pageQuery) {
+        return showCollectionService.all(pageQuery);
+    }
+
+    @GetMapping("/get/{id}")
+    public ShowCollection get(@PathVariable Long id) {
+        return showCollectionRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+    }
+
+    @PostMapping("/del/{id}")
+    public void del(@PathVariable Long id) {
+        showCollectionRepo.softDelete(id);
+    }
+
+    @GetMapping("/excel")
+    @ResponseBody
+    public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+        List<ShowCollection> data = all(pageQuery).getContent();
+        ExcelUtils.export(response, data);
+    }
+}
+

+ 60 - 0
src/main/java/com/izouma/nineth/web/ShowroomController.java

@@ -0,0 +1,60 @@
+package com.izouma.nineth.web;
+import com.izouma.nineth.domain.Showroom;
+import com.izouma.nineth.service.ShowroomService;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.exception.BusinessException;
+import com.izouma.nineth.repo.ShowroomRepo;
+import com.izouma.nineth.utils.ObjUtils;
+import com.izouma.nineth.utils.excel.ExcelUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+@RestController
+@RequestMapping("/showroom")
+@AllArgsConstructor
+public class ShowroomController extends BaseController {
+    private ShowroomService showroomService;
+    private ShowroomRepo showroomRepo;
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/save")
+    public Showroom save(@RequestBody Showroom record) {
+        if (record.getId() != null) {
+            Showroom orig = showroomRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            ObjUtils.merge(orig, record);
+            return showroomRepo.save(orig);
+        }
+        return showroomRepo.save(record);
+    }
+
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/all")
+    public Page<Showroom> all(@RequestBody PageQuery pageQuery) {
+        return showroomService.all(pageQuery);
+    }
+
+    @GetMapping("/get/{id}")
+    public Showroom get(@PathVariable Long id) {
+        return showroomRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+    }
+
+    @PostMapping("/del/{id}")
+    public void del(@PathVariable Long id) {
+        showroomRepo.softDelete(id);
+    }
+
+    @GetMapping("/excel")
+    @ResponseBody
+    public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+        List<Showroom> data = all(pageQuery).getContent();
+        ExcelUtils.export(response, data);
+    }
+}
+

+ 1 - 0
src/main/resources/genjson/ShowCollection.json

@@ -0,0 +1 @@
+{"tableName":"ShowCollection","className":"ShowCollection","remark":"展厅藏品","genTable":true,"genClass":true,"genList":false,"genForm":false,"genRouter":false,"javaPath":"/Users/qiufangchao/Desktop/project/raex_back/src/main/java/com/izouma/nineth","viewPath":"/Users/qiufangchao/Desktop/project/raex_back/src/main/vue/src/views","routerPath":"/Users/qiufangchao/Desktop/project/raex_back/src/main/vue/src","resourcesPath":"/Users/qiufangchao/Desktop/project/raex_back/src/main/resources","dataBaseType":"Mysql","fields":[{"name":"showroomId","modelName":"showroomId","remark":"showroomId","showInList":true,"showInForm":true,"formType":"number"},{"name":"collectionId","modelName":"collectionId","remark":"collectionId","showInList":true,"showInForm":true,"formType":"number"},{"name":"pic","modelName":"pic","remark":"pic","showInList":true,"showInForm":true,"formType":"number"},{"name":"sort","modelName":"sort","remark":"sort","showInList":true,"showInForm":true,"formType":"singleLineText"}],"readTable":false,"dataSourceCode":"dataSource","genJson":"","subtables":[],"update":false,"basePackage":"com.izouma.nineth","tablePackage":"com.izouma.nineth.domain.ShowCollection"}

+ 1 - 0
src/main/resources/genjson/Showroom.json

@@ -0,0 +1 @@
+{"tableName":"Showroom","className":"Showroom","remark":"展厅","genTable":true,"genClass":true,"genList":false,"genForm":false,"genRouter":false,"javaPath":"/Users/qiufangchao/Desktop/project/raex_back/src/main/java/com/izouma/nineth","viewPath":"/Users/qiufangchao/Desktop/project/raex_back/src/main/vue/src/views","routerPath":"/Users/qiufangchao/Desktop/project/raex_back/src/main/vue/src","resourcesPath":"/Users/qiufangchao/Desktop/project/raex_back/src/main/resources","dataBaseType":"Mysql","fields":[{"name":"userId","modelName":"userId","remark":"userId","showInList":true,"showInForm":true,"formType":"number"},{"name":"assetId","modelName":"assetId","remark":"assetId","showInList":true,"showInForm":true,"formType":"number"},{"name":"pic","modelName":"pic","remark":"pic","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"introduction","modelName":"introduction","remark":"introduction","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"likes","modelName":"likes","remark":"likes","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"share","modelName":"share","remark":"share","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"status","modelName":"status","remark":"status","showInList":true,"showInForm":true,"formType":"singleLineText"},{"name":"collections","modelName":"collections","remark":"collections","showInList":true,"showInForm":true,"formType":"singleLineText"}],"readTable":false,"dataSourceCode":"dataSource","genJson":"","subtables":[],"update":false,"basePackage":"com.izouma.nineth","tablePackage":"com.izouma.nineth.domain.Showroom"}