Преглед на файлове

店铺问答讨论优化。

dujian преди 3 месеца
родител
ревизия
f43b487750

+ 1 - 1
alien-store-platform/src/main/java/shop/alien/storeplatform/entity/StorePlatformDiscussion.java → alien-entity/src/main/java/shop/alien/entity/store/StorePlatformDiscussion.java

@@ -1,4 +1,4 @@
-package shop.alien.storeplatform.entity;
+package shop.alien.entity.store;
 
 import com.baomidou.mybatisplus.annotation.*;
 import com.fasterxml.jackson.annotation.JsonFormat;

+ 1 - 1
alien-store-platform/src/main/java/shop/alien/storeplatform/entity/StorePlatformDiscussionLike.java → alien-entity/src/main/java/shop/alien/entity/store/StorePlatformDiscussionLike.java

@@ -1,4 +1,4 @@
-package shop.alien.storeplatform.entity;
+package shop.alien.entity.store;
 
 import com.baomidou.mybatisplus.annotation.*;
 import io.swagger.annotations.ApiModel;

+ 1 - 1
alien-store-platform/src/main/java/shop/alien/storeplatform/vo/StorePlatformDiscussionReplyVo.java → alien-entity/src/main/java/shop/alien/entity/store/vo/StorePlatformDiscussionReplyVo.java

@@ -1,4 +1,4 @@
-package shop.alien.storeplatform.vo;
+package shop.alien.entity.store.vo;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import io.swagger.annotations.ApiModel;

+ 2 - 2
alien-store-platform/src/main/java/shop/alien/storeplatform/vo/StorePlatformDiscussionUserVo.java → alien-entity/src/main/java/shop/alien/entity/store/vo/StorePlatformDiscussionUserVo.java

@@ -1,10 +1,10 @@
-package shop.alien.storeplatform.vo;
+package shop.alien.entity.store.vo;
 
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
-import shop.alien.storeplatform.entity.StorePlatformDiscussion;
+import shop.alien.entity.store.StorePlatformDiscussion;
 
 /**
  * 店铺讨论人员VO

+ 2 - 2
alien-store-platform/src/main/java/shop/alien/storeplatform/mapper/StorePlatformDiscussionLikeMapper.java → alien-entity/src/main/java/shop/alien/mapper/StorePlatformDiscussionLikeMapper.java

@@ -1,8 +1,8 @@
-package shop.alien.storeplatform.mapper;
+package shop.alien.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
-import shop.alien.storeplatform.entity.StorePlatformDiscussionLike;
+import shop.alien.entity.store.StorePlatformDiscussionLike;
 
 /**
  * 店铺讨论点赞记录表 Mapper 接口

+ 2 - 2
alien-store-platform/src/main/java/shop/alien/storeplatform/mapper/StorePlatformDiscussionMapper.java → alien-entity/src/main/java/shop/alien/mapper/StorePlatformDiscussionMapper.java

@@ -1,8 +1,8 @@
-package shop.alien.storeplatform.mapper;
+package shop.alien.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
-import shop.alien.storeplatform.entity.StorePlatformDiscussion;
+import shop.alien.entity.store.StorePlatformDiscussion;
 
 /**
  * 店铺讨论表 Mapper 接口

+ 8 - 8
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformDiscussionController.java → alien-store/src/main/java/shop/alien/store/controller/StorePlatformDiscussionController.java

@@ -1,4 +1,4 @@
-package shop.alien.storeplatform.controller;
+package shop.alien.store.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import io.swagger.annotations.Api;
@@ -8,21 +8,21 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
-import shop.alien.storeplatform.entity.StorePlatformDiscussion;
-import shop.alien.storeplatform.service.StorePlatformDiscussionService;
-import shop.alien.storeplatform.vo.StorePlatformDiscussionReplyVo;
-import shop.alien.storeplatform.vo.StorePlatformDiscussionUserVo;
+import shop.alien.entity.store.StorePlatformDiscussion;
+import shop.alien.entity.store.vo.StorePlatformDiscussionReplyVo;
+import shop.alien.entity.store.vo.StorePlatformDiscussionUserVo;
+import shop.alien.store.service.StorePlatformDiscussionService;
 
 import java.util.List;
 
 /**
- * 商户平台-店铺讨论Controller
+ * 用户端-店铺讨论Controller
  *
- * @author alien
+ * @author dujian
  * @since 2025-12-30
  */
 @Slf4j
-@Api(tags = {"商户平台-店铺问答讨论"})
+@Api(tags = {"用户端-店铺问答讨论"})
 @RestController
 @RequestMapping("/platformStoreDiscussion")
 @RequiredArgsConstructor

+ 5 - 5
alien-store-platform/src/main/java/shop/alien/storeplatform/service/StorePlatformDiscussionService.java → alien-store/src/main/java/shop/alien/store/service/StorePlatformDiscussionService.java

@@ -1,17 +1,17 @@
-package shop.alien.storeplatform.service;
+package shop.alien.store.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
-import shop.alien.storeplatform.entity.StorePlatformDiscussion;
-import shop.alien.storeplatform.vo.StorePlatformDiscussionReplyVo;
-import shop.alien.storeplatform.vo.StorePlatformDiscussionUserVo;
+import shop.alien.entity.store.StorePlatformDiscussion;
+import shop.alien.entity.store.vo.StorePlatformDiscussionReplyVo;
+import shop.alien.entity.store.vo.StorePlatformDiscussionUserVo;
 
 import java.util.List;
 
 /**
  * 店铺讨论表 服务类
  *
- * @author alien
+ * @author dujian
  * @since 2025-12-30
  */
 public interface StorePlatformDiscussionService extends IService<StorePlatformDiscussion> {

+ 10 - 9
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/StorePlatformDiscussionServiceImpl.java → alien-store/src/main/java/shop/alien/store/service/impl/StorePlatformDiscussionServiceImpl.java

@@ -1,4 +1,4 @@
-package shop.alien.storeplatform.service.impl;
+package shop.alien.store.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -15,15 +15,15 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 import shop.alien.entity.store.LifeUser;
+import shop.alien.entity.store.StorePlatformDiscussion;
+import shop.alien.entity.store.StorePlatformDiscussionLike;
+import shop.alien.entity.store.vo.StorePlatformDiscussionReplyVo;
+import shop.alien.entity.store.vo.StorePlatformDiscussionUserVo;
 import shop.alien.mapper.LifeUserMapper;
-import shop.alien.storeplatform.entity.StorePlatformDiscussion;
-import shop.alien.storeplatform.entity.StorePlatformDiscussionLike;
-import shop.alien.storeplatform.mapper.StorePlatformDiscussionLikeMapper;
-import shop.alien.storeplatform.mapper.StorePlatformDiscussionMapper;
-import shop.alien.storeplatform.service.StorePlatformDiscussionService;
-import shop.alien.storeplatform.util.LoginUserUtil;
-import shop.alien.storeplatform.vo.StorePlatformDiscussionReplyVo;
-import shop.alien.storeplatform.vo.StorePlatformDiscussionUserVo;
+import shop.alien.mapper.StorePlatformDiscussionLikeMapper;
+import shop.alien.mapper.StorePlatformDiscussionMapper;
+import shop.alien.store.service.StorePlatformDiscussionService;
+import shop.alien.store.util.LoginUserUtil;
 import shop.alien.util.common.safe.DeepseekClient;
 
 import java.util.*;
@@ -187,6 +187,7 @@ public class StorePlatformDiscussionServiceImpl extends ServiceImpl<StorePlatfor
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean postTopic(StorePlatformDiscussion discussion) {
+        // 当前登录者
         Integer currentUserId = LoginUserUtil.getCurrentUserId();
         if (currentUserId == null) {
             throw new RuntimeException("请先登录再发表讨论");

+ 252 - 0
alien-store/src/main/java/shop/alien/store/util/LoginUserUtil.java

@@ -0,0 +1,252 @@
+package shop.alien.store.util;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import shop.alien.entity.store.StoreUser;
+import shop.alien.mapper.StoreUserMapper;
+import shop.alien.util.common.JwtUtil;
+
+/**
+ * 登录用户工具类
+ * 用于获取当前登录用户的信息
+ *
+ * @author dujian
+ * @since 2025-11-17
+ */
+@Slf4j
+@Component
+public class LoginUserUtil {
+
+    private static StoreUserMapper storeUserMapper;
+
+    @Autowired
+    public void setStoreUserMapper(StoreUserMapper storeUserMapper) {
+        LoginUserUtil.storeUserMapper = storeUserMapper;
+    }
+
+    /**
+     * 获取当前登录用户的ID
+     *
+     * @return 用户ID,如果未登录返回null
+     */
+    public static Integer getCurrentUserId() {
+        try {
+            JSONObject userInfo = JwtUtil.getCurrentUserInfo();
+            if (userInfo != null) {
+                return userInfo.getInteger("userId");
+            }
+        } catch (Exception e) {
+            log.error("LoginUserUtil.getCurrentUserId - 获取用户ID失败: {}", e.getMessage(), e);
+        }
+        return null;
+    }
+
+    /**
+     * 获取当前登录用户的手机号
+     *
+     * @return 手机号,如果未登录返回null
+     */
+    public static String getCurrentUserPhone() {
+        try {
+            JSONObject userInfo = JwtUtil.getCurrentUserInfo();
+            if (userInfo != null) {
+                return userInfo.getString("phone");
+            }
+        } catch (Exception e) {
+            log.error("LoginUserUtil.getCurrentUserPhone - 获取用户手机号失败: {}", e.getMessage(), e);
+        }
+        return null;
+    }
+
+    /**
+     * 获取当前登录用户的用户类型
+     *
+     * @return 用户类型,如果未登录返回null
+     */
+    public static String getCurrentUserType() {
+        try {
+            JSONObject userInfo = JwtUtil.getCurrentUserInfo();
+            if (userInfo != null) {
+                return userInfo.getString("userType");
+            }
+        } catch (Exception e) {
+            log.error("LoginUserUtil.getCurrentUserType - 获取用户类型失败: {}", e.getMessage(), e);
+        }
+        return null;
+    }
+
+    /**
+     * 获取当前登录用户的Token信息(JSONObject格式)
+     *
+     * @return 用户信息JSONObject,包含userId、phone、userType等字段,如果未登录返回null
+     */
+    public static JSONObject getCurrentUserInfo() {
+        try {
+            JSONObject userInfo = JwtUtil.getCurrentUserInfo();
+            if (userInfo != null) {
+                log.debug("LoginUserUtil.getCurrentUserInfo - 获取用户信息成功: userId={}, phone={}", 
+                        userInfo.getString("userId"), userInfo.getString("phone"));
+                return userInfo;
+            }
+        } catch (Exception e) {
+            log.error("LoginUserUtil.getCurrentUserInfo - 获取用户信息失败: {}", e.getMessage(), e);
+        }
+        return null;
+    }
+
+    /**
+     * 获取当前登录用户的完整商户用户信息(从数据库查询)
+     *
+     * @return StoreUser对象,如果未登录或查询失败返回null
+     */
+    public static StoreUser getCurrentStoreUser() {
+        try {
+            Integer userId = getCurrentUserId();
+            if (userId == null) {
+                log.warn("LoginUserUtil.getCurrentStoreUser - 用户未登录");
+                return null;
+            }
+
+            // 从数据库查询完整用户信息
+            StoreUser storeUser = storeUserMapper.selectById(userId);
+            if (storeUser != null) {
+                log.debug("LoginUserUtil.getCurrentStoreUser - 查询用户信息成功: userId={}, phone={}", 
+                        storeUser.getId(), storeUser.getPhone());
+            } else {
+                log.warn("LoginUserUtil.getCurrentStoreUser - 用户不存在: userId={}", userId);
+            }
+            return storeUser;
+        } catch (Exception e) {
+            log.error("LoginUserUtil.getCurrentStoreUser - 查询用户信息失败: {}", e.getMessage(), e);
+            return null;
+        }
+    }
+
+    /**
+     * 根据手机号获取商户用户信息
+     *
+     * @return StoreUser对象,如果未登录或查询失败返回null
+     */
+    public static StoreUser getCurrentStoreUserByPhone() {
+        try {
+            String phone = getCurrentUserPhone();
+            if (phone == null) {
+                log.warn("LoginUserUtil.getCurrentStoreUserByPhone - 用户未登录");
+                return null;
+            }
+
+            // 从数据库根据手机号查询用户信息
+            LambdaQueryWrapper<StoreUser> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(StoreUser::getPhone, phone);
+            StoreUser storeUser = storeUserMapper.selectOne(queryWrapper);
+            
+            if (storeUser != null) {
+                log.debug("LoginUserUtil.getCurrentStoreUserByPhone - 查询用户信息成功: userId={}, phone={}", 
+                        storeUser.getId(), storeUser.getPhone());
+            } else {
+                log.warn("LoginUserUtil.getCurrentStoreUserByPhone - 用户不存在: phone={}", phone);
+            }
+            return storeUser;
+        } catch (Exception e) {
+            log.error("LoginUserUtil.getCurrentStoreUserByPhone - 查询用户信息失败: {}", e.getMessage(), e);
+            return null;
+        }
+    }
+
+    /**
+     * 验证当前登录用户是否为指定用户
+     *
+     * @param userId 要验证的用户ID
+     * @return true-是当前用户, false-不是当前用户
+     */
+    public static boolean isCurrentUser(Integer userId) {
+        if (userId == null) {
+            return false;
+        }
+        Integer currentUserId = getCurrentUserId();
+        return userId.equals(currentUserId);
+    }
+
+    /**
+     * 验证当前用户是否已登录
+     *
+     * @return true-已登录, false-未登录
+     */
+    public static boolean isLogin() {
+        return getCurrentUserId() != null;
+    }
+
+    /**
+     * 验证当前用户类型是否为web端商户平台
+     *
+     * @return true-是商户平台用户, false-不是
+     */
+    public static boolean isStorePlatformUser() {
+        String userType = getCurrentUserType();
+        return "storePlatform".equals(userType);
+    }
+
+    /**
+     * 获取当前登录用户的门店ID
+     * 注意:需要先查询数据库获取完整用户信息
+     *
+     * @return 门店ID,如果未登录或用户无门店返回null
+     */
+    public static Integer getCurrentStoreId() {
+        try {
+            StoreUser storeUser = getCurrentStoreUser();
+            if (storeUser != null) {
+                return storeUser.getStoreId();
+            }
+        } catch (Exception e) {
+            log.error("LoginUserUtil.getCurrentStoreId - 获取门店ID失败: {}", e.getMessage(), e);
+        }
+        return null;
+    }
+
+    /**
+     * 获取当前登录用户的昵称
+     * 注意:需要先查询数据库获取完整用户信息
+     *
+     * @return 昵称,如果未登录返回null
+     */
+    public static String getCurrentNickName() {
+        try {
+            StoreUser storeUser = getCurrentStoreUser();
+            if (storeUser != null) {
+                return storeUser.getNickName();
+            }
+        } catch (Exception e) {
+            log.error("LoginUserUtil.getCurrentNickName - 获取昵称失败: {}", e.getMessage(), e);
+        }
+        return null;
+    }
+
+    /**
+     * 获取当前登录用户的真实姓名
+     * 注意:需要先查询数据库获取完整用户信息
+     *
+     * @return 真实姓名,如果未登录返回null
+     */
+    public static String getCurrentName() {
+        try {
+            StoreUser storeUser = getCurrentStoreUser();
+            if (storeUser != null) {
+                return storeUser.getName();
+            }
+        } catch (Exception e) {
+            log.error("LoginUserUtil.getCurrentName - 获取姓名失败: {}", e.getMessage(), e);
+        }
+        return null;
+    }
+}
+
+
+
+
+
+
+