Просмотр исходного кода

Merge branch 'master' of http://git.izouma.com/xiongzhu/9th

panhui 4 лет назад
Родитель
Сommit
1728ebf5e2

+ 22 - 0
src/main/java/com/izouma/nineth/domain/Appointment.java

@@ -0,0 +1,22 @@
+package com.izouma.nineth.domain;
+
+import io.swagger.annotations.ApiModel;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Entity;
+
+@Data
+@Entity
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@ApiModel("预约")
+public class Appointment extends BaseEntity {
+
+    private Long blindBoxId;
+
+    private Long userId;
+}

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

@@ -43,11 +43,24 @@ public class Asset extends BaseEntity {
     @Searchable
     private String name;
 
+    @ApiModelProperty("详情")
+    @Column(columnDefinition = "TEXT")
+    private String detail;
+
     @Column(columnDefinition = "TEXT")
     @Convert(converter = Collection.PropertyListConverter.class)
     @ApiModelProperty("特性")
     private List<Collection.CollectionProperty> properties;
 
+    @ApiModelProperty("是否可转售")
+    private boolean canResale;
+
+    @ApiModelProperty("版税比例")
+    private int royalties;
+
+    @ApiModelProperty("手续费比例")
+    private int serviceCharge;
+
     @ApiModelProperty("铸造者")
     @Searchable
     private String minter;
@@ -95,4 +108,8 @@ public class Asset extends BaseEntity {
     @ApiModelProperty("状态")
     @Enumerated(EnumType.STRING)
     private AssetStatus status;
+
+    private boolean publicShow;
+
+    private Long publicCollectionId;
 }

+ 13 - 0
src/main/java/com/izouma/nineth/domain/Collection.java

@@ -16,6 +16,7 @@ import org.apache.commons.lang3.StringUtils;
 
 import javax.persistence.*;
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.List;
 
 @Data
@@ -46,6 +47,16 @@ public class Collection extends BaseEntity {
     @ApiModelProperty("铸造者头像")
     private String minterAvatar;
 
+    @ApiModelProperty("铸造者")
+    @Searchable
+    private String owner;
+
+    @ApiModelProperty("铸造者ID")
+    private Long ownerId;
+
+    @ApiModelProperty("铸造者头像")
+    private String ownerAvatar;
+
     @ApiModelProperty("详情")
     @Column(columnDefinition = "TEXT")
     private String detail;
@@ -94,6 +105,8 @@ public class Collection extends BaseEntity {
     @ApiModelProperty("手续费比例")
     private int serviceCharge;
 
+    @ApiModelProperty("盲盒开售时间")
+    private LocalDateTime startTime;
 
     @Data
     public static class CollectionProperty {

+ 13 - 0
src/main/java/com/izouma/nineth/domain/Order.java

@@ -47,11 +47,24 @@ public class Order extends BaseEntity {
     @Column(columnDefinition = "TEXT")
     private List<String> pic;
 
+    @ApiModelProperty("详情")
+    @Column(columnDefinition = "TEXT")
+    private String detail;
+
     @Column(columnDefinition = "TEXT")
     @Convert(converter = Collection.PropertyListConverter.class)
     @ApiModelProperty("特性")
     private List<Collection.CollectionProperty> properties;
 
+    @ApiModelProperty("是否可转售")
+    private boolean canResale;
+
+    @ApiModelProperty("版税比例")
+    private int royalties;
+
+    @ApiModelProperty("手续费比例")
+    private int serviceCharge;
+
     @ApiModelProperty("类型")
     @Enumerated(EnumType.STRING)
     private CollectionType type;

+ 1 - 0
src/main/java/com/izouma/nineth/dto/CollectionDTO.java

@@ -6,4 +6,5 @@ import lombok.Data;
 @Data
 public class CollectionDTO extends Collection {
     private boolean liked;
+    private boolean appointment;
 }

+ 15 - 0
src/main/java/com/izouma/nineth/repo/AppointmentRepo.java

@@ -0,0 +1,15 @@
+package com.izouma.nineth.repo;
+
+import com.izouma.nineth.domain.Appointment;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface AppointmentRepo extends JpaRepository<Appointment, Long>, JpaSpecificationExecutor<Appointment> {
+
+    Optional<Appointment> findFirstByBlindBoxId(Long id);
+
+    List<Appointment> findByUserId(Long userId);
+}

+ 1 - 0
src/main/java/com/izouma/nineth/security/WebSecurityConfig.java

@@ -86,6 +86,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/user/all").permitAll()
                 .antMatchers("/user/get/*").permitAll()
                 .antMatchers("/user/forgotPassword").permitAll()
+                .antMatchers("/sysConfig/get/*").permitAll()
                 // all other requests need to be authenticated
                 .anyRequest().authenticated().and()
                 // make sure we use stateless session; session won't be used to

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

@@ -5,6 +5,8 @@ import com.izouma.nineth.dto.NFT;
 import com.izouma.nineth.dto.NFTAccount;
 import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.enums.AssetStatus;
+import com.izouma.nineth.enums.CollectionSource;
+import com.izouma.nineth.enums.CollectionType;
 import com.izouma.nineth.event.CreateAssetEvent;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.AssetRepo;
@@ -19,6 +21,8 @@ import org.springframework.data.domain.Page;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+
 @Service
 @AllArgsConstructor
 @Slf4j
@@ -27,6 +31,7 @@ public class AssetService {
     private AssetRepo          assetRepo;
     private UserRepo           userRepo;
     private NFTService         nftService;
+    private CollectionRepo     collectionRepo;
     private ApplicationContext applicationContext;
 
     public Page<Asset> all(PageQuery pageQuery) {
@@ -53,8 +58,12 @@ public class AssetService {
                         .minterId(order.getMinterId())
                         .minterAvatar(order.getMinterAvatar())
                         .name(order.getName())
+                        .detail(order.getDetail())
                         .pic(order.getPic())
                         .properties(order.getProperties())
+                        .canResale(order.isCanResale())
+                        .royalties(order.getRoyalties())
+                        .serviceCharge(order.getServiceCharge())
                         .tokenId(nft.getTokenId())
                         .blockNumber(nft.getBlockNumber())
                         .txHash(nft.getTxHash())
@@ -92,8 +101,12 @@ public class AssetService {
                         .minterId(winItem.getMinterId())
                         .minterAvatar(winItem.getMinterAvatar())
                         .name(winItem.getName())
+                        .detail(winItem.getDetail())
                         .pic(winItem.getPics())
                         .properties(winItem.getProperties())
+                        .canResale(winItem.isCanResale())
+                        .royalties(winItem.getRoyalties())
+                        .serviceCharge(winItem.getServiceCharge())
                         .tokenId(nft.getTokenId())
                         .blockNumber(nft.getBlockNumber())
                         .txHash(nft.getTxHash())
@@ -110,4 +123,48 @@ public class AssetService {
         }
         applicationContext.publishEvent(new CreateAssetEvent(this, false, order, null));
     }
+
+    public void publicShow(Long id) {
+        Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        if (asset.isPublicShow()) {
+            return;
+        }
+        User owner = userRepo.findById(asset.getUserId()).orElseThrow(new BusinessException("用户不存在"));
+        Collection collection = Collection.builder()
+                .name(asset.getName())
+                .pics(asset.getPic())
+                .minter(asset.getMinter())
+                .minterId(asset.getMinterId())
+                .minterAvatar(asset.getMinterAvatar())
+                .owner(owner.getNickname())
+                .ownerId(owner.getId())
+                .ownerAvatar(owner.getAvatar())
+                .detail(asset.getDetail())
+                .type(CollectionType.DEFAULT)
+                .source(CollectionSource.TRANSFER)
+                .sale(0)
+                .stock(1)
+                .total(1)
+                .onShelf(true)
+                .salable(false)
+                .price(BigDecimal.valueOf(0))
+                .properties(asset.getProperties())
+                .canResale(asset.isCanResale())
+                .royalties(asset.getRoyalties())
+                .serviceCharge(asset.getServiceCharge())
+                .build();
+        collectionRepo.save(collection);
+        asset.setPublicShow(true);
+        asset.setPublicCollectionId(collection.getId());
+    }
+
+    public void cancelPublic(Long id) {
+        Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        if (!asset.isPublicShow()) {
+            return;
+        }
+        Collection collection = collectionRepo.findById(asset.getPublicCollectionId())
+                .orElseThrow(new BusinessException("无展示记录"));
+
+    }
 }

+ 39 - 8
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -7,9 +7,7 @@ import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.dto.UserDTO;
 import com.izouma.nineth.enums.CollectionType;
 import com.izouma.nineth.exception.BusinessException;
-import com.izouma.nineth.repo.BlindBoxItemRepo;
-import com.izouma.nineth.repo.CollectionRepo;
-import com.izouma.nineth.repo.LikeRepo;
+import com.izouma.nineth.repo.*;
 import com.izouma.nineth.utils.JpaUtils;
 import com.izouma.nineth.utils.SecurityUtils;
 import lombok.AllArgsConstructor;
@@ -25,6 +23,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import javax.transaction.Transactional;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -37,6 +36,8 @@ public class CollectionService {
     private CollectionRepo   collectionRepo;
     private LikeRepo         likeRepo;
     private BlindBoxItemRepo blindBoxItemRepo;
+    private AppointmentRepo  appointmentRepo;
+    private UserRepo         userRepo;
 
     public Page<Collection> all(PageQuery pageQuery) {
         pageQuery.getQuery().put("del", false);
@@ -53,10 +54,13 @@ public class CollectionService {
     }
 
     public Collection create(Collection record) {
-        User user = SecurityUtils.getAuthenticatedUser();
-        record.setMinter(user.getNickname());
-        record.setMinterId(user.getId());
-        record.setMinterAvatar(user.getAvatar());
+        User minter = userRepo.findById(record.getMinterId()).orElse(SecurityUtils.getAuthenticatedUser());
+        record.setMinter(minter.getNickname());
+        record.setMinterId(minter.getId());
+        record.setMinterAvatar(minter.getAvatar());
+        record.setOwner(minter.getNickname());
+        record.setOwnerId(minter.getId());
+        record.setOwnerAvatar(minter.getAvatar());
         record.setStock(record.getTotal());
         record.setSale(0);
         return collectionRepo.save(record);
@@ -74,6 +78,9 @@ public class CollectionService {
                 List<Like> list = likeRepo.findByUserIdAndCollectionId(SecurityUtils.getAuthenticatedUser().getId(),
                         collection.getId());
                 collectionDTO.setLiked(!list.isEmpty());
+                if (collection.getType() == CollectionType.BLIND_BOX) {
+                    collectionDTO.setAppointment(appointmentRepo.findFirstByBlindBoxId(collection.getId()).isPresent());
+                }
             }
         }
         return collectionDTO;
@@ -81,14 +88,19 @@ public class CollectionService {
 
     public List<CollectionDTO> toDTO(List<Collection> collections) {
         List<Like> likes = new ArrayList<>();
+        List<Appointment> appointments = new ArrayList<>();
         if (SecurityUtils.getAuthenticatedUser() != null) {
             likes.addAll(likeRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId()));
+            appointments.addAll(appointmentRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId()));
         }
         return collections.stream().parallel().map(collection -> {
             CollectionDTO dto = toDTO(collection, false);
             if (!likes.isEmpty()) {
                 dto.setLiked(likes.stream().anyMatch(l -> l.getCollectionId().equals(collection.getId())));
             }
+            if (!appointments.isEmpty()) {
+                dto.setAppointment(appointments.stream().anyMatch(a -> a.getBlindBoxId().equals(collection.getId())));
+            }
             return dto;
         }).collect(Collectors.toList());
     }
@@ -113,10 +125,13 @@ public class CollectionService {
             }
         }
 
-        User user = SecurityUtils.getAuthenticatedUser();
+        User user = userRepo.findById(blindBox.getMinterId()).orElse(SecurityUtils.getAuthenticatedUser());
         blindBox.setMinter(user.getNickname());
         blindBox.setMinterId(user.getId());
         blindBox.setMinterAvatar(user.getAvatar());
+        blindBox.setOwner(user.getNickname());
+        blindBox.setOwnerId(user.getId());
+        blindBox.setOwnerAvatar(user.getAvatar());
         blindBox.setStock(blindBox.getTotal());
         blindBox.setSale(0);
         collectionRepo.save(blindBox);
@@ -139,4 +154,20 @@ public class CollectionService {
 
         return blindBox;
     }
+
+    public void appointment(Long id, Long userId) {
+        Collection collection = collectionRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        if (collection.getType() != CollectionType.BLIND_BOX) {
+            throw new BusinessException("非盲盒,无需预约");
+        }
+
+        if (collection.getStartTime().isBefore(LocalDateTime.now())) {
+            throw new BusinessException("盲盒已开售,无需预约");
+        }
+
+        appointmentRepo.save(Appointment.builder()
+                .userId(userId)
+                .blindBoxId(id)
+                .build());
+    }
 }

+ 4 - 0
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -99,7 +99,11 @@ public class OrderService {
                 .collectionId(collectionId)
                 .name(collection.getName())
                 .pic(collection.getPics())
+                .detail(collection.getDetail())
                 .properties(collection.getProperties())
+                .canResale(collection.isCanResale())
+                .royalties(collection.getRoyalties())
+                .serviceCharge(collection.getServiceCharge())
                 .type(collection.getType())
                 .minter(minter.getNickname())
                 .minterAvatar(minter.getAvatar())

+ 7 - 1
src/main/java/com/izouma/nineth/web/AssetController.java

@@ -1,4 +1,5 @@
 package com.izouma.nineth.web;
+
 import com.izouma.nineth.domain.Asset;
 import com.izouma.nineth.service.AssetService;
 import com.izouma.nineth.dto.PageQuery;
@@ -20,7 +21,7 @@ import java.util.List;
 @AllArgsConstructor
 public class AssetController extends BaseController {
     private AssetService assetService;
-    private AssetRepo assetRepo;
+    private AssetRepo    assetRepo;
 
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
@@ -56,5 +57,10 @@ public class AssetController extends BaseController {
         List<Asset> data = all(pageQuery).getContent();
         ExcelUtils.export(response, data);
     }
+
+    @PostMapping("/publicShow")
+    public void publicShow(@RequestParam Long id) {
+        assetService.publicShow(id);
+    }
 }
 

+ 5 - 0
src/main/java/com/izouma/nineth/web/CollectionController.java

@@ -87,5 +87,10 @@ public class CollectionController extends BaseController {
     public Collection createBlindBox(@RequestBody CreateBlindBox createBlindBox) {
         return collectionService.createBlindBox(createBlindBox);
     }
+
+    @PostMapping("/appointment")
+    public void appointment(@RequestParam Long id) {
+        collectionService.appointment(id, SecurityUtils.getAuthenticatedUser().getId());
+    }
 }
 

+ 2 - 2
src/main/resources/application.yaml

@@ -79,8 +79,8 @@ aliyun:
   access-key-id: PXzJyah5rZfWHIIH
   access-key-secret: e1MS6j0wypXJrw8CM0hObZu8qKbfah
   oss-end-point: oss-cn-hangzhou.aliyuncs.com
-  oss-bucket-name: awesomeadmin
-  oss-domain: https://awesomeadmin.oss-cn-hangzhou.aliyuncs.com
+  oss-bucket-name: 9space
+  oss-domain: https://9space.oss-cn-hangzhou.aliyuncs.com
 general:
   host: http://nft.9space.vip
 mychain: