Kaynağa Gözat

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

panhui 4 yıl önce
ebeveyn
işleme
9226984ef8

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

@@ -88,7 +88,7 @@ public class Asset extends BaseEntity {
     @ApiModelProperty("区块高度")
     @ApiModelProperty("区块高度")
     private BigInteger blockNumber;
     private BigInteger blockNumber;
 
 
-    @ApiModelProperty("购买hash")
+    @ApiModelProperty("ipfs地址")
     private String ipfsUrl;
     private String ipfsUrl;
 
 
     @ApiModelProperty("购买价格")
     @ApiModelProperty("购买价格")

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

@@ -1,5 +1,6 @@
 package com.izouma.nineth.service;
 package com.izouma.nineth.service;
 
 
+import com.github.kevinsawicki.http.HttpRequest;
 import com.izouma.nineth.domain.*;
 import com.izouma.nineth.domain.*;
 import com.izouma.nineth.dto.NFT;
 import com.izouma.nineth.dto.NFT;
 import com.izouma.nineth.dto.NFTAccount;
 import com.izouma.nineth.dto.NFTAccount;
@@ -13,6 +14,10 @@ import com.izouma.nineth.repo.AssetRepo;
 import com.izouma.nineth.repo.CollectionRepo;
 import com.izouma.nineth.repo.CollectionRepo;
 import com.izouma.nineth.repo.UserRepo;
 import com.izouma.nineth.repo.UserRepo;
 import com.izouma.nineth.utils.JpaUtils;
 import com.izouma.nineth.utils.JpaUtils;
+import io.ipfs.api.IPFS;
+import io.ipfs.api.MerkleNode;
+import io.ipfs.api.NamedStreamable;
+import io.ipfs.multihash.Multihash;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -21,6 +26,7 @@ import org.springframework.data.domain.Page;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.io.File;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 
 
 @Service
 @Service
@@ -70,6 +76,7 @@ public class AssetService {
                         .gasUsed(nft.getGasUsed())
                         .gasUsed(nft.getGasUsed())
                         .price(order.getPrice())
                         .price(order.getPrice())
                         .status(AssetStatus.NORMAL)
                         .status(AssetStatus.NORMAL)
+                        .ipfsUrl(ipfsUpload(order.getPic().get(0)))
                         .build();
                         .build();
                 assetRepo.save(asset);
                 assetRepo.save(asset);
                 applicationContext.publishEvent(new CreateAssetEvent(this, true, order, asset));
                 applicationContext.publishEvent(new CreateAssetEvent(this, true, order, asset));
@@ -113,6 +120,7 @@ public class AssetService {
                         .gasUsed(nft.getGasUsed())
                         .gasUsed(nft.getGasUsed())
                         .price(order.getPrice())
                         .price(order.getPrice())
                         .status(AssetStatus.NORMAL)
                         .status(AssetStatus.NORMAL)
+                        .ipfsUrl(ipfsUpload(winItem.getPics().get(0)))
                         .build();
                         .build();
                 assetRepo.save(asset);
                 assetRepo.save(asset);
                 applicationContext.publishEvent(new CreateAssetEvent(this, true, order, asset));
                 applicationContext.publishEvent(new CreateAssetEvent(this, true, order, asset));
@@ -124,6 +132,22 @@ public class AssetService {
         applicationContext.publishEvent(new CreateAssetEvent(this, false, order, null));
         applicationContext.publishEvent(new CreateAssetEvent(this, false, order, null));
     }
     }
 
 
+    public String ipfsUpload(String url) {
+        try {
+            IPFS ipfs = new IPFS("121.40.132.44", 5001);
+            HttpRequest request = HttpRequest.get(url);
+            File file = File.createTempFile("ipfs", ".tmp");
+            request.receive(file);
+            NamedStreamable.FileWrapper file1 = new NamedStreamable.FileWrapper(file);
+            MerkleNode put = ipfs.add(file1).get(0);
+            Multihash multihash = ipfs.pin.add(put.hash).get(0);
+            log.info("上传ipfs成功 {}", multihash.toBase58());
+            return multihash.toBase58();
+        } catch (Exception e) {
+        }
+        return null;
+    }
+
     public void publicShow(Long id) {
     public void publicShow(Long id) {
         Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
         Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
         if (asset.isPublicShow()) {
         if (asset.isPublicShow()) {

+ 17 - 5
src/main/java/com/izouma/nineth/service/UserService.java

@@ -36,6 +36,10 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
@@ -56,11 +60,16 @@ public class UserService {
 
 
     public Page<User> all(PageQuery pageQuery) {
     public Page<User> all(PageQuery pageQuery) {
         Specification<User> specification = JpaUtils.toSpecification(pageQuery, User.class);
         Specification<User> specification = JpaUtils.toSpecification(pageQuery, User.class);
-        if (pageQuery.getQuery().containsKey("hasRole")) {
-            String roleName = (String) pageQuery.getQuery().get("hasRole");
-            specification = specification.and((Specification<User>) (root, criteriaQuery, criteriaBuilder) ->
-                    criteriaBuilder.isMember(Authority.get(AuthorityName.valueOf(roleName)), root.get("authorities")));
-        }
+
+        specification = specification.and((Specification<User>) (root, criteriaQuery, criteriaBuilder) -> {
+            List<Predicate> and = new ArrayList<>();
+            and.add(criteriaBuilder.notEqual(root.get("id"), 1L));
+            if (pageQuery.getQuery().containsKey("hasRole")) {
+                String roleName = (String) pageQuery.getQuery().get("hasRole");
+                and.add(criteriaBuilder.isMember(Authority.get(AuthorityName.valueOf(roleName)), root.get("authorities")));
+            }
+            return criteriaBuilder.and(and.toArray(new Predicate[0]));
+        });
         return userRepo.findAll(specification, JpaUtils.toPageRequest(pageQuery));
         return userRepo.findAll(specification, JpaUtils.toPageRequest(pageQuery));
     }
     }
 
 
@@ -121,6 +130,9 @@ public class UserService {
     public User loginByPhonePwd(String phone, String password) {
     public User loginByPhonePwd(String phone, String password) {
         User user = userRepo.findByPhoneAndDelFalse(phone).orElseThrow(new BusinessException("账号或密码错误"));
         User user = userRepo.findByPhoneAndDelFalse(phone).orElseThrow(new BusinessException("账号或密码错误"));
 
 
+        if (StringUtils.isEmpty(user.getPassword())) {
+            throw new BusinessException("账号或密码错误");
+        }
         if (StringUtils.isNoneEmpty(user.getPassword()) &&
         if (StringUtils.isNoneEmpty(user.getPassword()) &&
                 new BCryptPasswordEncoder().matches(password, user.getPassword())) {
                 new BCryptPasswordEncoder().matches(password, user.getPassword())) {
             throw new BusinessException("账号或密码错误");
             throw new BusinessException("账号或密码错误");

+ 21 - 0
src/main/nine-space/.prettierrc.js

@@ -0,0 +1,21 @@
+module.exports = {
+    printWidth: 120,
+    singleQuote: true,
+    tabWidth: 4,
+    arrowParens: 'avoid',
+    trailingComma: 'none',
+    overrides: [
+        {
+            files: '*.html',
+            options: {
+                parser: 'html'
+            }
+        },
+        {
+            files: '*.vue',
+            options: {
+                parser: 'vue'
+            }
+        }
+    ]
+};

+ 1 - 0
src/main/nine-space/src/views/Discover.vue

@@ -160,6 +160,7 @@ export default {
             size: 20,
             size: 20,
             query: {
             query: {
               onShelf: true,
               onShelf: true,
+              del: false
             },
             },
             sort: "createdAt,desc",
             sort: "createdAt,desc",
           },
           },

+ 1 - 0
src/main/nine-space/src/views/Home.vue

@@ -161,6 +161,7 @@ export default {
             query: {
             query: {
               type: type,
               type: type,
               onShelf: true,
               onShelf: true,
+              del: false
             },
             },
             sort: "createdAt,desc",
             sort: "createdAt,desc",
           },
           },

+ 1 - 0
src/main/nine-space/src/views/creator/Detail.vue

@@ -202,6 +202,7 @@ export default {
               type: this.type,
               type: this.type,
               onShelf: this.onShelf,
               onShelf: this.onShelf,
               minterId: this.info.id,
               minterId: this.info.id,
+              del: false
             },
             },
             sort: this.sort,
             sort: this.sort,
           },
           },

+ 1 - 0
src/main/nine-space/src/views/product/List.vue

@@ -127,6 +127,7 @@ export default {
             query: {
             query: {
               type: this.type,
               type: this.type,
               onShelf: true,
               onShelf: true,
+              del: false
             },
             },
             sort: this.sort,
             sort: this.sort,
           },
           },

+ 1 - 0
src/main/nine-space/src/views/product/Search.vue

@@ -100,6 +100,7 @@ export default {
               onShelf: true,
               onShelf: true,
               type: this.type,
               type: this.type,
               minterId: this.minterId,
               minterId: this.minterId,
+              del: false
             },
             },
             sort: "createdAt,desc",
             sort: "createdAt,desc",
             search: this.search,
             search: this.search,

+ 5 - 1
src/test/java/com/izouma/nineth/CommonTest.java

@@ -1,5 +1,6 @@
 package com.izouma.nineth;
 package com.izouma.nineth;
 
 
+import com.github.kevinsawicki.http.HttpRequest;
 import com.izouma.nineth.domain.BaseEntity;
 import com.izouma.nineth.domain.BaseEntity;
 import com.izouma.nineth.domain.BlindBoxItem;
 import com.izouma.nineth.domain.BlindBoxItem;
 import com.izouma.nineth.domain.User;
 import com.izouma.nineth.domain.User;
@@ -204,7 +205,10 @@ public class CommonTest {
     @Test
     @Test
     public void testIPFS() throws IOException {
     public void testIPFS() throws IOException {
         IPFS ipfs = new IPFS("121.40.132.44", 5001);
         IPFS ipfs = new IPFS("121.40.132.44", 5001);
-        NamedStreamable.FileWrapper file1 = new NamedStreamable.FileWrapper(new File("/Users/drew/Desktop/截屏2021-10-14 下午5.09.58.png"));
+        HttpRequest request = HttpRequest.get("https://awesomeadmin.oss-cn-hangzhou.aliyuncs.com/image/2021-10-21-16-44-52kZqxuwhH.gif");
+        File file = File.createTempFile("ipfs", ".tmp");
+        request.receive(file);
+        NamedStreamable.FileWrapper file1 = new NamedStreamable.FileWrapper(file);
         MerkleNode put = ipfs.add(file1).get(0);
         MerkleNode put = ipfs.add(file1).get(0);
         Multihash multihash = ipfs.pin.add(put.hash).get(0);
         Multihash multihash = ipfs.pin.add(put.hash).get(0);
         System.out.println(put.hash.toBase58());
         System.out.println(put.hash.toBase58());