Prechádzať zdrojové kódy

Merge branch 'dev' of http://git.izouma.com/xiongzhu/raex_back into dev

panhui 4 rokov pred
rodič
commit
001d5c0d6c

+ 3 - 0
src/main/java/com/izouma/nineth/repo/UserRepo.java

@@ -243,4 +243,7 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
 
     @Query("select u.id from User u where u.del = false and u.level = 99")
     List<Long> findIdByLevel();
+
+    @Query("select u.id from User u where u.del = false and u.phone in ?1")
+    List<Long> findIdByPhones(Collection<String> phones);
 }

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

@@ -118,7 +118,7 @@ public class GiftOrderService {
                 .userId(userId)
                 .assetId(assetId)
                 .toUserId(toUserId)
-                .gasPrice(sysConfigService.getBigDecimal("gas_fee"))
+                .gasPrice(sysConfigService.getBigDecimal("gift_gas_fee"))
                 .status(OrderStatus.NOT_PAID)
                 .build();
         giftOrder.setPayMethod(PayMethod.FREE);
@@ -178,7 +178,7 @@ public class GiftOrderService {
                 .userId(userId)
                 .assetId(assetId)
                 .toUserId(toUserId)
-                .gasPrice(sysConfigService.getBigDecimal("gas_fee"))
+                .gasPrice(sysConfigService.getBigDecimal("gift_gas_fee"))
                 .status(OrderStatus.NOT_PAID)
                 .build();
         return giftOrderRepo.save(giftOrder);

+ 12 - 1
src/main/java/com/izouma/nineth/service/OrderPayService.java

@@ -32,6 +32,7 @@ import java.util.Optional;
 public class OrderPayService {
     private static String PAY_CHANNEL = "sandPay";
 
+    private final OrderService       orderService;
     private final OrderRepo          orderRepo;
     private final MintOrderRepo      mintOrderRepo;
     private final GiftOrderRepo      giftOrderRepo;
@@ -125,7 +126,17 @@ public class OrderPayService {
     }
 
     public void confirmOrderAgreement(String requestId, String paymentOrderId, String code) {
-        payEaseService.payConfirm(requestId, paymentOrderId, code);
+        try {
+            payEaseService.payConfirm(requestId, paymentOrderId, code);
+        } catch (BusinessException e) {
+            try {
+                new Thread(() -> {
+                    orderService.cancel(Long.parseLong(requestId));
+                }).start();
+            } catch (Exception ee) {
+            }
+            throw e;
+        }
     }
 
     @Cacheable(value = "payOrder", key = "'gift#'+#orderId")

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

@@ -218,6 +218,7 @@ public class OrderService {
                 throw new BusinessException("该藏品当前不可购买");
             }
 
+
             AtomicInteger userMax = new AtomicInteger();
             userPropertyRepo.findById(userId).ifPresent(userProperty -> userMax.set(userProperty.getMaxCount()));
 
@@ -230,9 +231,16 @@ public class OrderService {
                     count = orderRepo.countByUserIdAndCollectionIdAndStatusIn(userId, collectionId, Arrays
                             .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
                 }
-                if (count >= userMax.addAndGet(collection.getMaxCount()) ) {
-                    throw new BusinessException("限购" + userMax.get() + "件");
+                if (userMax.get() > 0) {
+                    if (count >= userMax.get()) {
+                        throw new BusinessException("限购" + userMax.get() + "件");
+                    }
+                } else {
+                    if (count >= collection.getMaxCount()) {
+                        throw new BusinessException("限购" + collection.getMaxCount() + "件");
+                    }
                 }
+
             }
             User user = null;
             if (ObjectUtils.isNotEmpty(collection.getMinimumCharge()) && collection.getMinimumCharge()
@@ -370,7 +378,6 @@ public class OrderService {
 
         AtomicInteger userMax = new AtomicInteger();
         userPropertyRepo.findById(userId).ifPresent(userProperty -> userMax.set(userProperty.getMaxCount()));
-        int limit = userMax.addAndGet(collection.getMaxCount());
 
         if (collection.getMaxCount() > 0) {
             if (StringUtils.isNotBlank(collection.getCountId())) {
@@ -382,7 +389,7 @@ public class OrderService {
             }
         }
         Map<String, Object> map = new HashMap<>();
-        map.put("limit", limit);
+        map.put("limit", userMax.get() > 0 ? userMax.get() : collection.getMaxCount());
         map.put("count", count);
         return map;
     }

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

@@ -102,7 +102,7 @@ public class PayEaseService {
         if (!"SUCCESS".equals(status)) {
             String error = responseData.getString("error");
             String cause = responseData.getString("cause");
-            throw new BusinessException(error);
+            throw new BusinessException(error + "[" + cause + "]");
         }
         String bindStatus = responseData.getString("bindStatus");
         if (!"SUCCESS".equals(bindStatus)) {

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

@@ -564,7 +564,7 @@ public class UserService {
     public void verifyTradeCode(Long userId, String tradeCode) {
         User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
         if (!passwordEncoder.matches(tradeCode, user.getTradeCode())) {
-            throw new BusinessException("校验失败");
+            throw new BusinessException("交易密码错误");
         }
     }
 

+ 15 - 0
src/main/resources/static/return.html

@@ -0,0 +1,15 @@
+<!doctype html>
+<html lang="zh">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport"
+          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
+    <meta http-equiv="X-UA-Compatible" content="ie=edge">
+    <title>订单已完成</title>
+</head>
+<body>
+<div>
+    订单已完成,请返回APP查看
+</div>
+</body>
+</html>

+ 36 - 6
src/test/java/com/izouma/nineth/repo/CollectionRepoTest.java

@@ -1,21 +1,29 @@
 package com.izouma.nineth.repo;
 
 import com.izouma.nineth.ApplicationTests;
+import com.izouma.nineth.domain.Collection;
+import com.izouma.nineth.enums.OrderStatus;
+import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.service.AssetService;
+import org.apache.commons.lang3.StringUtils;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.util.Arrays;
 import java.util.List;
-
-import static org.junit.Assert.*;
+import java.util.concurrent.atomic.AtomicInteger;
 
 public class CollectionRepoTest extends ApplicationTests {
     @Autowired
-    private CollectionRepo collectionRepo;
+    private CollectionRepo   collectionRepo;
+    @Autowired
+    private AssetService     assetService;
     @Autowired
-    private AssetService   assetService;
+    private TagRepo          tagRepo;
     @Autowired
-    private TagRepo        tagRepo;
+    private UserPropertyRepo userPropertyRepo;
+    @Autowired
+    private OrderRepo        orderRepo;
 
     @Test
     public void updateCDN() {
@@ -32,7 +40,29 @@ public class CollectionRepoTest extends ApplicationTests {
     }
 
     @Test
-    public void testTag() {
+    public void testMaxCount() {
+        Collection collection = collectionRepo.findById(8017401L).orElse(null);
+        AtomicInteger userMax = new AtomicInteger();
+        userPropertyRepo.findById(9972L).ifPresent(userProperty -> userMax.set(userProperty.getMaxCount()));
+        if (collection.getMaxCount() > 0) {
+            int count;
+            if (StringUtils.isNotBlank(collection.getCountId())) {
+                count = orderRepo.countByUserIdAndCountIdAndStatusIn(9972L, collection.getCountId(), Arrays
+                        .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
+            } else {
+                count = orderRepo.countByUserIdAndCollectionIdAndStatusIn(9972L, 8017401L, Arrays
+                        .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
+            }
+            if (userMax.get() > 0) {
+                if (count >= userMax.get()) {
+                    throw new BusinessException("限购" + userMax.get() + "件");
+                }
+            } else {
+                if (count >= collection.getMaxCount()) {
+                    throw new BusinessException("限购" + collection.getMaxCount() + "件");
+                }
+            }
 
+        }
     }
 }

+ 164 - 7
src/test/java/com/izouma/nineth/repo/UserPropertyRepoTest.java

@@ -1,15 +1,19 @@
 package com.izouma.nineth.repo;
 
+import com.alibaba.excel.EasyExcel;
 import com.izouma.nineth.ApplicationTests;
 import com.izouma.nineth.domain.Asset;
+import com.izouma.nineth.domain.User;
 import com.izouma.nineth.domain.UserProperty;
+import com.izouma.nineth.dto.AirDropExcelDTO;
 import com.izouma.nineth.enums.AssetStatus;
+import com.izouma.nineth.utils.excel.UploadDataListener;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.io.DataOutput;
+import java.io.File;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
@@ -52,8 +56,8 @@ public class UserPropertyRepoTest extends ApplicationTests {
         userIds.forEach(id -> {
             UserProperty userProperty = userPropertyRepo.findById(id).orElse(new UserProperty(id, 0));
             userProperty.setMaxCount(userProperty.getMaxCount() + 1);
-            if (userProperty.getMaxCount() > 5) {
-                userProperty.setMaxCount(5);
+            if (userProperty.getMaxCount() > 6) {
+                userProperty.setMaxCount(6);
             }
             userPropertyRepo.save(userProperty);
         });
@@ -72,11 +76,164 @@ public class UserPropertyRepoTest extends ApplicationTests {
             }
             UserProperty userProperty = userPropertyRepo.findById(key).orElse(new UserProperty(key, 0));
             userProperty.setMaxCount(userProperty.getMaxCount() + size);
-            if (userProperty.getMaxCount() > 5) {
-                userProperty.setMaxCount(5);
+            if (userProperty.getMaxCount() > 6) {
+                userProperty.setMaxCount(6);
             }
             userPropertyRepo.save(userProperty);
         });
 
+        //凤鸣寺
+        File file = new File("/Users/qiufangchao/Desktop/mingdan.xlsx");
+        UploadDataListener<AirDropExcelDTO> listener = new UploadDataListener<>();
+        List<AirDropExcelDTO> dtos = EasyExcel.read(file, AirDropExcelDTO.class, listener)
+                .sheet()
+                .doReadSync();
+        List<Long> userIds2 = userRepo.findIdByPhones(dtos.stream()
+                .map(AirDropExcelDTO::getPhone)
+                .collect(Collectors.toSet()));
+        System.out.println(userIds2);
+        userIds2.forEach(id -> {
+            UserProperty userProperty = userPropertyRepo.findById(id).orElse(new UserProperty(id, 0));
+            userProperty.setMaxCount(userProperty.getMaxCount() + 1);
+            if (userProperty.getMaxCount() > 6) {
+                userProperty.setMaxCount(6);
+            }
+            userPropertyRepo.save(userProperty);
+        });
+
+        //vip
+        File file1 = new File("/Users/qiufangchao/Desktop/VIP.xlsx");
+        UploadDataListener<AirDropExcelDTO> listener1 = new UploadDataListener<>();
+        List<AirDropExcelDTO> dtos1 = EasyExcel.read(file1, AirDropExcelDTO.class, listener1)
+                .sheet()
+                .doReadSync();
+        Set<String> userIds3 = dtos1.stream()
+                .map(AirDropExcelDTO::getPhone)
+                .collect(Collectors.toSet());
+        System.out.println(userIds3);
+        userIds3.forEach(id -> {
+            UserProperty userProperty = userPropertyRepo.findById(Long.parseLong(id))
+                    .orElse(new UserProperty(Long.parseLong(id), 0));
+            userProperty.setMaxCount(userProperty.getMaxCount() + 1);
+            if (userProperty.getMaxCount() > 6) {
+                userProperty.setMaxCount(6);
+            }
+            userPropertyRepo.save(userProperty);
+        });
+
+
+        //-1
+        Iterable<UserProperty> all = userPropertyRepo.findAll();
+        all.forEach(p -> {
+            if (p.getMaxCount() > 1) {
+                p.setMaxCount(p.getMaxCount() - 1);
+                userPropertyRepo.save(p);
+            }
+        });
+
     }
+
+    @Test
+    public void setByphone() {
+        File file = new File("/Users/qiufangchao/Desktop/mingdan.xlsx");
+        UploadDataListener<AirDropExcelDTO> listener = new UploadDataListener<>();
+        List<AirDropExcelDTO> dtos = EasyExcel.read(file, AirDropExcelDTO.class, listener)
+                .sheet()
+                .doReadSync();
+//        List<Long> userIds = userRepo.findIdByPhones(dtos.stream()
+//                .map(AirDropExcelDTO::getPhone)
+//                .collect(Collectors.toSet()));
+//        System.out.println(userIds);
+
+        List<User> users = userRepo.findByPhoneInAndDelFalse(dtos.stream()
+                .map(AirDropExcelDTO::getPhone)
+                .collect(Collectors.toSet()));
+
+        Map<String, Long> userMap = users.stream().collect(Collectors.toMap(User::getPhone, User::getId));
+        dtos.forEach(dto -> {
+            Long aLong = userMap.get(dto.getPhone());
+            if (aLong == null) {
+                System.out.println(dto.getPhone());
+            }
+        });
+
+
+//        userIds.forEach(id -> {
+//            UserProperty userProperty = userPropertyRepo.findById(id).orElse(new UserProperty(id, 0));
+//            userProperty.setMaxCount(userProperty.getMaxCount() + 1);
+//            if (userProperty.getMaxCount() > 6) {
+//                userProperty.setMaxCount(6);
+//            }
+//            userPropertyRepo.save(userProperty);
+//        });
+    }
+
+    @Test
+    public void setById() {
+        File file = new File("/Users/qiufangchao/Desktop/VIP.xlsx");
+        UploadDataListener<AirDropExcelDTO> listener = new UploadDataListener<>();
+        List<AirDropExcelDTO> dtos = EasyExcel.read(file, AirDropExcelDTO.class, listener)
+                .sheet()
+                .doReadSync();
+        Set<String> userIds = dtos.stream()
+                .map(AirDropExcelDTO::getPhone)
+                .collect(Collectors.toSet());
+        System.out.println(userIds);
+        userIds.forEach(id -> {
+
+            UserProperty userProperty = userPropertyRepo.findById(Long.parseLong(id))
+                    .orElse(new UserProperty(Long.parseLong(id), 0));
+            userProperty.setMaxCount(userProperty.getMaxCount() + 1);
+            if (userProperty.getMaxCount() > 6) {
+                userProperty.setMaxCount(6);
+            }
+            userPropertyRepo.save(userProperty);
+        });
+    }
+
+    @Test
+    public void statistic() {
+        Map<Long, Integer> map = new HashMap<>();
+        //凤鸣寺
+        File file = new File("/Users/qiufangchao/Desktop/mingdan.xlsx");
+        UploadDataListener<AirDropExcelDTO> listener = new UploadDataListener<>();
+        List<AirDropExcelDTO> dtos = EasyExcel.read(file, AirDropExcelDTO.class, listener)
+                .sheet()
+                .doReadSync();
+        List<Long> userIds = userRepo.findIdByPhones(dtos.stream()
+                .map(AirDropExcelDTO::getPhone)
+                .collect(Collectors.toSet()));
+        userIds.forEach(id -> map.merge(id, 1, Integer::sum));
+        //封神星主
+        List<Long> userIds1 = userRepo.findIdByLevel();
+        userIds1.forEach(id -> map.merge(id, 1, Integer::sum));
+
+
+        //OASIS004:绿洲朋克战神3D持斧模型 2516069L 或  OASIS002: 绿洲朋克猴王3D旋转眺望模型 2514968L
+        //OASISPUNK007:OASISPUNK绿洲朋克族人共治会荣誉勋章 5050947L
+        //冠军赛 · 李小龙80周年纪念勋章 7275L
+        List<Asset> assets = assetRepo.findByCollectionIdInAndStatus(Arrays.asList(2516069L, 2514968L, 5050947L, 7275L), AssetStatus.NORMAL);
+        Map<Long, List<Asset>> collect = assets.stream().collect(Collectors.groupingBy(Asset::getOwnerId));
+        collect.forEach((key, value) -> {
+            List<Long> ids = value.stream().map(Asset::getCollectionId).distinct().collect(Collectors.toList());
+            int size = ids.size();
+            if (ids.contains(2516069L) && ids.contains(2514968L)) {
+                size -= 1;
+            }
+            map.merge(key, size, Integer::sum);
+        });
+        map.forEach((key, value) -> System.out.println(key + "," + value));
+    }
+
+    @Test
+    public void test(){
+        Iterable<UserProperty> all = userPropertyRepo.findAll();
+        all.forEach(p -> {
+            if (p.getMaxCount() > 1) {
+                p.setMaxCount(p.getMaxCount() - 1);
+                userPropertyRepo.save(p);
+            }
+        });
+    }
+
 }