Browse Source

Merge branch 'dev'

# Conflicts:
#	src/test/java/com/izouma/nineth/service/CollectionServiceTest.java
xiongzhu 4 years ago
parent
commit
06bff53955

+ 2 - 0
src/main/java/com/izouma/nineth/config/GeneralProperties.java

@@ -30,4 +30,6 @@ public class GeneralProperties {
     private String  updateQuotaTopic;
     private String  broadcastEventGroup;
     private String  broadcastEventTopic;
+    private String  registerGroup;
+    private String  registerTopic;
 }

+ 2 - 0
src/main/java/com/izouma/nineth/domain/BaseEntity.java

@@ -25,6 +25,8 @@ public abstract class BaseEntity {
     @ExcelProperty("ID")
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
+//    @GeneratedValue(generator = "snowFlakeId")
+//    @GenericGenerator(name = "snowFlakeId", strategy = "com.izouma.nineth.utils.SnowflakeIdGenerator")
     private Long id;
 
     @ExcelIgnore

+ 17 - 0
src/main/java/com/izouma/nineth/event/RegisterEvent.java

@@ -0,0 +1,17 @@
+package com.izouma.nineth.event;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class RegisterEvent {
+    private String phone;
+    private String code;
+    private String password;
+    private String inviteCode;
+    private Long   invitor;
+    private Long   collectionId;
+}

+ 47 - 0
src/main/java/com/izouma/nineth/listener/RegisterListener.java

@@ -0,0 +1,47 @@
+package com.izouma.nineth.listener;
+
+import com.izouma.nineth.domain.User;
+import com.izouma.nineth.event.RegisterEvent;
+import com.izouma.nineth.service.UserService;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.rocketmq.spring.annotation.ConsumeMode;
+import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
+import org.apache.rocketmq.spring.core.RocketMQListener;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+@Slf4j
+@AllArgsConstructor
+@RocketMQMessageListener(
+        consumerGroup = "${general.register-group}",
+        topic = "${general.register-topic}",
+        consumeMode = ConsumeMode.ORDERLY)
+@ConditionalOnProperty(value = "general.notify-server", havingValue = "false", matchIfMissing = true)
+public class RegisterListener implements RocketMQListener<RegisterEvent> {
+    private UserService                   userService;
+    private RedisTemplate<String, Object> redisTemplate;
+
+    @Override
+    public void onMessage(RegisterEvent registerEvent) {
+        Map<String, Object> map = new HashMap<>();
+        try {
+            User user = userService.phoneRegister(registerEvent.getPhone(), registerEvent.getCode(),
+                    registerEvent.getPassword(), registerEvent.getInviteCode(),
+                    registerEvent.getInvitor(), registerEvent.getCollectionId());
+            map.put("status", "success");
+            map.put("data", user);
+            redisTemplate.opsForValue().set("register::" + registerEvent.getPhone(), map, Duration.ofSeconds(600));
+        } catch (Exception e) {
+            map.put("status", "fail");
+            map.put("data", e.getMessage());
+            redisTemplate.opsForValue().set("register::" + registerEvent.getPhone(), map, Duration.ofSeconds(600));
+        }
+    }
+}

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

@@ -46,7 +46,7 @@ public class CacheService {
     public void clearCollectionList() {
     }
 
-    @Scheduled(cron = "1 0 0 ? * 2")
+    @Scheduled(cron = "0 0 0 ? * MON")
     @CacheEvict(value = "weekTop", allEntries = true)
     public void clearWeekTop() {
     }

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

@@ -6,12 +6,14 @@ import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
 import com.huifu.adapay.core.exception.BaseAdaPayException;
 import com.izouma.nineth.TokenHistory;
 import com.izouma.nineth.config.Constants;
+import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.domain.Collection;
 import com.izouma.nineth.domain.*;
 import com.izouma.nineth.dto.*;
 import com.izouma.nineth.enums.AuthStatus;
 import com.izouma.nineth.enums.AuthorityName;
 import com.izouma.nineth.event.AccountCreatedEvent;
+import com.izouma.nineth.event.RegisterEvent;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.*;
 import com.izouma.nineth.security.Authority;
@@ -32,6 +34,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpUser;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.springframework.beans.BeanUtils;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
@@ -40,6 +43,7 @@ import org.springframework.core.env.Environment;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
@@ -56,24 +60,27 @@ import java.util.stream.Collectors;
 @Slf4j
 @AllArgsConstructor
 public class UserService {
-    private UserRepo              userRepo;
-    private WxMaService           wxMaService;
-    private WxMpService           wxMpService;
-    private SmsService            smsService;
-    private StorageService        storageService;
-    private JwtTokenUtil          jwtTokenUtil;
-    private FollowService         followService;
-    private FollowRepo            followRepo;
-    private IdentityAuthRepo      identityAuthRepo;
-    private SysConfigService      sysConfigService;
-    private UserBankCardRepo      userBankCardRepo;
-    private InviteRepo            inviteRepo;
-    private NFTService            nftService;
-    private CacheService          cacheService;
-    private TokenHistoryRepo      tokenHistoryRepo;
-    private CollectionRepo        collectionRepo;
-    private AdapayMerchantService adapayMerchantService;
-    private Environment           env;
+    private UserRepo                      userRepo;
+    private WxMaService                   wxMaService;
+    private WxMpService                   wxMpService;
+    private SmsService                    smsService;
+    private StorageService                storageService;
+    private JwtTokenUtil                  jwtTokenUtil;
+    private FollowService                 followService;
+    private FollowRepo                    followRepo;
+    private IdentityAuthRepo              identityAuthRepo;
+    private SysConfigService              sysConfigService;
+    private UserBankCardRepo              userBankCardRepo;
+    private InviteRepo                    inviteRepo;
+    private NFTService                    nftService;
+    private CacheService                  cacheService;
+    private TokenHistoryRepo              tokenHistoryRepo;
+    private CollectionRepo                collectionRepo;
+    private AdapayMerchantService         adapayMerchantService;
+    private Environment                   env;
+    private RocketMQTemplate              rocketMQTemplate;
+    private GeneralProperties             generalProperties;
+    private RedisTemplate<String, Object> redisTemplate;
 
     public User update(User user) {
         if (!SecurityUtils.hasRole(AuthorityName.ROLE_ADMIN)) {
@@ -148,7 +155,7 @@ public class UserService {
         if (StringUtils.isNotBlank(userRegister.getPassword())) {
             user.setPassword(new BCryptPasswordEncoder().encode(userRegister.getPassword()));
         }
-        user = userRepo.saveAndFlush(user);
+        user = userRepo.save(user);
         if (Arrays.asList(env.getActiveProfiles()).contains("prod")) {
             nftService.createAccount(user.getId());
         }
@@ -236,6 +243,16 @@ public class UserService {
         return user;
     }
 
+    public String mqRegister(String phone, String code, String password, String inviteCode, Long invitor, Long collectionId) {
+        rocketMQTemplate.convertAndSend(generalProperties.getRegisterTopic(),
+                new RegisterEvent(phone, code, password, inviteCode, invitor, collectionId));
+        return phone;
+    }
+
+    public Object getRegisterResult(String phone) {
+        return redisTemplate.opsForValue().get("register::" + phone);
+    }
+
     public User testPhoneRegister() {
         String phone = "19" + RandomStringUtils.randomNumeric(11);
         String password = "123456";

+ 25 - 0
src/main/java/com/izouma/nineth/web/AuthenticationController.java

@@ -22,6 +22,8 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Objects;
 
 @Slf4j
@@ -77,6 +79,29 @@ public class AuthenticationController {
         return jwtTokenUtil.generateToken(JwtUserFactory.create(user));
     }
 
+    @PostMapping("/mqPhoneRegister")
+    @ApiOperation(value = "手机号密码注册")
+    public String mqPhoneRegister(String phone, String code, String password, String inviteCode, Long invitor,
+                                  Long collectionId, String captcha, String captchaKey) {
+//        boolean verify = captchaService.verify(captchaKey, captcha);
+//        if (!verify) {
+//            throw new BusinessException("验证码错误");
+//        }
+        return userService.mqRegister(phone, code, password, inviteCode, invitor, collectionId);
+    }
+
+    @GetMapping("/registerResult")
+    public Object registerResult(String phone) {
+        Object res = userService.getRegisterResult(phone);
+        Map<String, Object> map = new HashMap<>();
+        if (res == null) {
+            map.put("status", "pending");
+            return map;
+        } else {
+            return res;
+        }
+    }
+
     @PostMapping("/testphoneRegister")
     @ApiOperation(value = "手机号密码注册")
     public String phonePwdLogin() {

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

@@ -30,7 +30,7 @@ spring:
     password: tetQsjw!u4!c5$URduo7BH
     hikari:
       minimum-idle: 20
-      maximum-pool-size: 300
+      maximum-pool-size: 3000
       auto-commit: true
       idle-timeout: 7200
       max-lifetime: 1800000
@@ -55,6 +55,7 @@ spring:
       # 打开PSCache,并且指定每个连接上PSCache的大小
       poolPreparedStatements: true
       maxPoolPreparedStatementPerConnectionSize: 20
+      query-timeout: 300000
       # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
       filters: stat,wall,slf4j
       # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
@@ -157,6 +158,8 @@ general:
   update-quota-topic: update-quota-topic-dev
   broadcast-event-group: broadcast-event-group-dev
   broadcast-event-topic: broadcast-event-topic-dev
+  register-group: register-group-dev
+  register-topic: register-topic-dev
 mychain:
   rest:
     bizid: a00e36c5
@@ -212,7 +215,7 @@ rocketmq:
 spring:
   profiles: test
   datasource:
-    url: jdbc:mysql://rm-wz9sc79f5255780opqo.mysql.rds.aliyuncs.com/raex_test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
+    url: jdbc:mysql://rm-wz9sc79f5255780op.mysql.rds.aliyuncs.com/raex_test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
     username: raex_server
     password: tetQsjw!u4!c5$URduo7BH
   redis:
@@ -237,6 +240,8 @@ general:
   update-quota-topic: update-quota-topic-test
   broadcast-event-group: broadcast-event-group-test
   broadcast-event-topic: broadcast-event-topic-test
+  register-group: register-group-test
+  register-topic: register-topic-test
 ---
 
 spring:
@@ -268,6 +273,8 @@ general:
   update-quota-topic: update-quota-topic-test1
   broadcast-event-group: broadcast-event-group-test1
   broadcast-event-topic: broadcast-event-topic-test1
+  register-group: register-group-test1
+  register-topic: register-topic-test1
 wx:
   pay:
     notify-url: https://test1.raex.vip/notify/order/weixin
@@ -324,6 +331,8 @@ general:
   update-quota-topic: update-quota-topic
   broadcast-event-group: broadcast-event-group
   broadcast-event-topic: broadcast-event-topic
+  register-group: register-group
+  register-topic: register-topic
 wx:
   pay:
     notify-url: https://www.raex.vip/notify/order/weixin
@@ -370,6 +379,8 @@ general:
   update-activity-stock-topic: update-activity-stock-topic
   update-quota-group: update-quota-group
   update-quota-topic: update-quota-topic
+  register-group: register-group
+  register-topic: register-topic
 wx:
   pay:
     notify-url: https://www.raex.vip/notify/order/weixin
@@ -416,6 +427,8 @@ general:
   update-quota-topic: update-quota-topic-test
   broadcast-event-group: broadcast-event-group-test
   broadcast-event-topic: broadcast-event-topic-test
+  register-group: register-group-test
+  register-topic: register-topic-test
 rocketmq:
   name-server: 172.29.50.102:9876
   producer:

+ 1 - 1
src/test/java/com/izouma/nineth/service/CollectionServiceTest.java

@@ -140,7 +140,7 @@ class CollectionServiceTest extends ApplicationTests {
 
     @Test
     public void savePoint() {
-        collectionService.savePoint(196332L, LocalDateTime.now()).forEach(System.out::println);
+        collectionService.savePoint(3749128L, LocalDateTime.now()).forEach(System.out::println);
     }
 
 }