lutong před 5 hodinami
rodič
revize
1c43e330f7

+ 9 - 0
alien-gateway/src/main/java/shop/alien/gateway/feign/StoreServiceFeign.java

@@ -2,7 +2,10 @@ package shop.alien.gateway.feign;
 
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
+import shop.alien.entity.analytics.dto.AnalyticsUserRegisterDTO;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.LifeSysMenu;
 
@@ -19,4 +22,10 @@ public interface StoreServiceFeign {
      */
     @GetMapping(value = "/sys/menu/getMenuByUserId")
     R<List<LifeSysMenu>> getMenuByUserId(@RequestParam("userId") Long userId, @RequestParam(name = "ifTree",required = false) Long ifTree);
+
+    /**
+     * 用户注册埋点(登录即注册场景由后端上报)
+     */
+    @PostMapping("/analytics/front/user/register")
+    R<String> trackUserRegister(@RequestBody AnalyticsUserRegisterDTO dto);
 }

+ 29 - 0
alien-gateway/src/main/java/shop/alien/gateway/service/LifeUserService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -12,6 +13,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
+import shop.alien.entity.analytics.dto.AnalyticsUserRegisterDTO;
 import shop.alien.entity.result.R;
 import shop.alien.entity.second.LifeUserLog;
 import shop.alien.entity.second.SecondRiskControlRecord;
@@ -25,6 +27,7 @@ import shop.alien.entity.store.vo.LifeUserVo;
 import shop.alien.gateway.config.BaseRedisService;
 import shop.alien.gateway.config.RiskControlProperties;
 import shop.alien.gateway.feign.SecondServiceFeign;
+import shop.alien.gateway.feign.StoreServiceFeign;
 import shop.alien.gateway.mapper.LifeUserLogGatewayMapper;
 import shop.alien.gateway.mapper.LifeUserGatewayMapper;
 import shop.alien.mapper.second.SecondRiskControlRecordMapper;
@@ -41,10 +44,13 @@ import java.util.stream.Collectors;
 /**
  * 用户
  */
+@Slf4j
 @Service
 @RequiredArgsConstructor
 public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser> {
 
+    private static final String USER_REGISTER_CHANNEL = "app_user";
+
     private final LifeUserGatewayMapper lifeUserMapper;
 
     private final LifeUserLogGatewayMapper lifeUserLogMapper;
@@ -53,6 +59,8 @@ public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser
 
     private final SecondServiceFeign alienSecondFeign;
 
+    private final StoreServiceFeign storeServiceFeign;
+
     private final ActivityInviteConfigService activityInviteConfigService;
 
     private final SecondRiskControlRecordMapper secondRiskControlRecordMapper;
@@ -167,6 +175,7 @@ public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser
                 addLifeUserSessionToken(phoneNum, token);
                 // 二手平台登录log,同一个macip登录多账号记录
                 addLifeUserLogInfo(user2, macIp);
+                trackNewUserRegister(user2);
                 userVo.setHasLoginPassword(StringUtils.isNotBlank(user2.getPassword()));
                 fillLogoutEndTime(userVo, user2);
 
@@ -194,6 +203,26 @@ public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser
         }
     }
 
+    /**
+     * 登录即注册:新用户创建成功后由后端上报注册埋点,避免前端无法区分登录/注册。
+     */
+    private void trackNewUserRegister(LifeUser user) {
+        if (user == null || user.getId() == null) {
+            return;
+        }
+        try {
+            AnalyticsUserRegisterDTO dto = new AnalyticsUserRegisterDTO();
+            dto.setEventId(UUID.randomUUID().toString().replace("-", ""));
+            dto.setUserId(user.getId().longValue());
+            dto.setUserPhone(user.getUserPhone());
+            dto.setRegisterTime(user.getCreatedTime() != null ? user.getCreatedTime() : new Date());
+            dto.setChannel(USER_REGISTER_CHANNEL);
+            storeServiceFeign.trackUserRegister(dto);
+        } catch (Exception e) {
+            log.warn("用户注册埋点上报失败: userId={}", user.getId(), e);
+        }
+    }
+
     private String getToken(String phoneNum, String userVo, Map<String, String> tokenMap) {
         int effectiveTimeInt = Integer.parseInt(effectiveTime.substring(0, effectiveTime.length() - 1));
         String effectiveTimeUnit = effectiveTime.substring(effectiveTime.length() - 1);

+ 1 - 0
alien-job/src/main/java/shop/alien/job/feign/AlienStoreFeign.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
+import shop.alien.entity.store.vo.AccountLogoutCompleteResultVo;
 
 import java.util.Map;