فهرست منبع

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

panhui 4 سال پیش
والد
کامیت
2ac2cf007b

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

@@ -85,6 +85,7 @@ public class User extends BaseEntity implements Serializable {
 
     private int sales;
 
+    @Column(columnDefinition = "TEXT")
     private String intro;
 
     private String bg;

+ 4 - 0
src/main/java/com/izouma/nineth/repo/OrderRepo.java

@@ -29,4 +29,8 @@ public interface OrderRepo extends JpaRepository<Order, Long>, JpaSpecificationE
     int countByCollectionIdAndStatusIn(Long collectionId, Iterable<OrderStatus> orderStatuses);
 
     List<Order> findByStatus(OrderStatus orderStatus);
+
+    @Query("select count(o) from Order o join Collection c on o.collectionId = c.id " +
+            "where c.minterId = ?1 and c.source = 'OFFICIAL' and o.status <> 'NOT_PAID' and o.status <> 'CANCELLED'")
+    long countSales(Long userId);
 }

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

@@ -151,4 +151,11 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
     @Modifying
     @Transactional
     void updateHistoryToUser(Long userId);
+
+    @Transactional
+    @Modifying
+    @Query("update User u set u.sales = ?2 where u.id = ?1")
+    void setSales(Long userId, int sales);
+
+    List<User> findByAuthoritiesContains(Authority authority);
 }

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

@@ -67,7 +67,7 @@ public class GiftOrderService {
         if (!asset.getUserId().equals(userId)) {
             throw new BusinessException("无权限");
         }
-        if (!toUserId.equals(userId)) {
+        if (toUserId.equals(userId)) {
             throw new BusinessException("不能送给自己");
         }
         if (!(asset.getStatus() == AssetStatus.NORMAL)) {

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

@@ -27,6 +27,7 @@ import com.izouma.nineth.event.CreateAssetEvent;
 import com.izouma.nineth.event.TransferAssetEvent;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.*;
+import com.izouma.nineth.security.Authority;
 import com.izouma.nineth.utils.JpaUtils;
 import com.izouma.nineth.utils.SnowflakeIdWorker;
 import lombok.AllArgsConstructor;
@@ -49,7 +50,6 @@ import java.math.RoundingMode;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
-import java.util.stream.Collectors;
 
 @Service
 @AllArgsConstructor
@@ -517,18 +517,11 @@ public class OrderService {
     public void setNumberRecursive(Asset asset) {
     }
 
-
+    @Scheduled(fixedRate = 120000)
     public void setSales() {
-        List<Collection> collections = collectionRepo.findAll();
-        List<User> minters = userRepo.findAllById(collections.stream().map(Collection::getMinterId)
-                .collect(Collectors.toSet()));
+        List<User> minters = userRepo.findByAuthoritiesContains(Authority.get(AuthorityName.ROLE_MINTER));
         for (User minter : minters) {
-            List<Collection> list = collections.stream().filter(c -> minter.getId().equals(c.getMinterId()))
-                    .collect(Collectors.toList());
-            minter.setSales((int) orderRepo.findByCollectionIdIn(list.stream().map(Collection::getId)
-                            .collect(Collectors.toSet())).stream()
-                    .filter(o -> o.getStatus() != OrderStatus.CANCELLED).count());
-            userRepo.save(minter);
+            userRepo.setSales(minter.getId(), (int) orderRepo.countSales(minter.getId()));
         }
     }
 

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

@@ -44,6 +44,7 @@ import org.springframework.stereotype.Service;
 import javax.persistence.criteria.Predicate;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 @Service
@@ -394,7 +395,7 @@ public class UserService {
 
     public Map<String, Object> searchByPhoneAdmin(String phoneStr) {
         List<String> phone = Arrays.stream(phoneStr.replaceAll("\n", " ")
-                        .replaceAll("\r\n", "")
+                        .replaceAll("\r\n", " ")
                         .split(" "))
                 .map(String::trim)
                 .filter(s -> !StringUtils.isEmpty(s))
@@ -454,4 +455,45 @@ public class UserService {
             throw new BusinessException("未绑定");
         }
     }
+
+    public Map<String, Object> batchRegister(String phones, String defaultPassword) {
+        List<String> exist = new ArrayList<>();
+        List<String> err = new ArrayList<>();
+        List<String> success = new ArrayList<>();
+        Arrays.stream(phones.replaceAll(",", " ")
+                .replaceAll(",", " ")
+                .replaceAll("\n", " ")
+                .replaceAll("\r\n", " ")
+                .split(" ")).forEach(phone -> {
+
+            if (userRepo.findByPhoneAndDelFalse(phone).isPresent()) {
+                exist.add(phone);
+            } else {
+                if (!Pattern.matches("^1[3-9]\\d{9}]$", phone)) {
+                    err.add(phone);
+                } else {
+                    try {
+                        String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+                        User user = create(UserRegister.builder()
+                                .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
+                                .username(name)
+                                .nickname(name)
+                                .password(defaultPassword)
+                                .avatar(Constants.DEFAULT_AVATAR)
+                                .phone(phone)
+                                .build());
+                        success.add(phone);
+                    } catch (Exception e) {
+                        log.error("注册失败", e);
+                        err.add(phone);
+                    }
+                }
+            }
+        });
+        Map<String, Object> map = new HashMap<>();
+        map.put("exist", exist);
+        map.put("error", err);
+        map.put("success", success);
+        return map;
+    }
 }

+ 21 - 0
src/main/java/com/izouma/nineth/utils/SnowflakeIdGenerator.java

@@ -0,0 +1,21 @@
+package com.izouma.nineth.utils;
+
+import org.hibernate.HibernateException;
+import org.hibernate.engine.spi.SharedSessionContractImplementor;
+import org.hibernate.id.IdentifierGenerator;
+
+import java.io.Serializable;
+
+public class SnowflakeIdGenerator implements IdentifierGenerator {
+
+    private final SnowflakeIdWorker snowflakeIdWorker;
+
+    public SnowflakeIdGenerator() {
+        this.snowflakeIdWorker = new SnowflakeIdWorker(0, 0);
+    }
+
+    @Override
+    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
+        return snowflakeIdWorker.nextId();
+    }
+}

+ 6 - 0
src/main/java/com/izouma/nineth/web/UserController.java

@@ -225,6 +225,12 @@ public class UserController extends BaseController {
     public void removeBankCard() throws BaseAdaPayException {
         userService.removeBankCard(SecurityUtils.getAuthenticatedUser().getId());
     }
+
+    @PreAuthorize("hasAnyRole('ADMIN')")
+    @PostMapping("/batchRegister")
+    public Map<String, Object> batchRegister(@RequestParam String phones, @RequestParam String defaultPassword) {
+        return userService.batchRegister(phones, defaultPassword);
+    }
 }
 
 

+ 1 - 1
src/main/nine-space/src/views/Mine.vue

@@ -52,7 +52,7 @@
                 <div class="sub" :class="{ 'van-multi-ellipsis--l2': !showMore }">
                     {{ userInfo.intro }}
                 </div>
-                <div class="sub-right" v-if="userInfo && userInfo.intro.length > 50">
+                <div class="sub-right" v-if="userInfo && userInfo.intro && userInfo.intro.length > 50">
                     <div @click="showMore = !showMore">{{ showMore ? '收起' : '展开' }}</div>
                 </div>
 

+ 1 - 1
src/main/vue/src/views/BlindBoxEdit.vue

@@ -424,7 +424,7 @@ export default {
                 id: [{ required: true, message: '请选择作品' }],
                 total: [{ required: true, message: '请输入数量' }]
             },
-            cateogories: ['收藏品', '数字艺术', '门票', '游戏', '音乐', '使用', '其他']
+            cateogories: ['勋章', '收藏品', '数字艺术', '门票', '游戏', '音乐', '使用', '其他']
         };
     },
     methods: {

+ 1 - 1
src/main/vue/src/views/CollectionEdit.vue

@@ -411,7 +411,7 @@ export default {
                 { label: '用户铸造', value: 'USER' },
                 { label: '转让', value: 'TRANSFER' }
             ],
-            cateogories: ['收藏品', '数字艺术', '门票', '游戏', '音乐', '使用', '其他'],
+            cateogories: ['勋章', '收藏品', '数字艺术', '门票', '游戏', '音乐', '使用', '其他'],
             privilegeOptions: [],
             showPrivilegeEditDialog: false,
             privilegeForm: {},