Sfoglia il codice sorgente

refactor(app): 重构 App相关接口和功能

- 新增 AppDetailController,用于处理 App 详情信息查询
- 移除 AppHomeController 中的详情查询相关接口
- 更新 AppUserController,添加 RedisUtil 和 SecurityManager 的使用描述
- 调整 Place- 修改 IDetailService 接口InfoVO 中的类名
- 更新 ShiroConfig,允许匿名访问登录接口
- 优化 UserServiceImpl 中的登录逻辑,集成 Shiro 认证
SheepHy 2 settimane fa
parent
commit
68b002e883

+ 2 - 1
national-motion-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -101,7 +101,8 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/sys/common/static/**", "anon");//图片预览 &下载文件不限制token
         filterChainDefinitionMap.put("/sys/common/pdf/**", "anon");//pdf预览
         filterChainDefinitionMap.put("/app/home/homeInfo", "anon");//APP首页接口
-        filterChainDefinitionMap.put("/app/home/getMsg", "anon");//APP首页接口
+//        filterChainDefinitionMap.put("/app/home/getMsg", "anon");//APP首页接口
+        filterChainDefinitionMap.put("/app/user/loginByCode", "anon");//APP首页接口
 
 //        filterChainDefinitionMap.put("/app/user/**", "anon");//小程序相关
 

+ 63 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/controller/AppDetailController.java

@@ -0,0 +1,63 @@
+package org.jeecg.modules.app.controller;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.app.service.IDetailService;
+import org.jeecg.modules.app.vo.CourseInfoVO;
+import org.jeecg.modules.app.vo.PlaceInfoVO;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+@Slf4j
+@Tag(name = "App首页相关接口")
+@RestController
+@RequestMapping("/app/detail")
+public class AppDetailController {
+    @Resource
+    private IDetailService detailService;
+    /**
+     * @Author SheepHy
+     * @Description 门店详情信息查询
+     * @Date 19:41 2025/7/7
+     * @Param id 门店id
+     * @return PlaceInfoVO {@link PlaceInfoVO}
+     **/
+    @GetMapping("/getPlaceInfo")
+    @Operation(summary = "门店详情信息查询 ")
+    public Result<PlaceInfoVO> getPlaceInfo(@RequestParam @Schema(description="门店ID") String id){
+        return Result.ok(detailService.getPlaceInfo(id));
+    }
+
+    /**
+     * @Author SheepHy
+     * @Description 课程详情
+     * @Date 13:36 2025/7/8
+     * @Param id 课程id
+     * @return CourseInfoVO {@link CourseInfoVO}
+     **/
+    @GetMapping("/getCourseInfo")
+    @Operation(summary = "课程详情")
+    public Result<CourseInfoVO> getCourseInfo(@RequestParam @Schema(description="课程ID")String id, @RequestParam double latitude,@RequestParam double longitude){
+        return Result.ok(detailService.getCourseInfo(id, latitude, longitude));
+    }
+
+    /**
+     * @Author SheepHy
+     * @Description 根据课程类型查询课程列表
+     * @Date 9:52 2025/7/9
+     * @Param type 课程类型
+     * @return List<PlaceInfoVO.CourseInfoVO>
+     **/
+    @GetMapping("/courseInfoVOList")
+    @Operation(summary = "根据课程类型查询课程列表")
+    public Result<List<PlaceInfoVO.CourseInfoVO>> courseInfoVOList(@RequestParam @Schema(description="课程类型")String type, @RequestParam @Schema(description="课程ID")String id){
+        return Result.ok(detailService.courseInfoVOList(type, id));
+    }
+}

+ 4 - 42
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/controller/AppHomeController.java

@@ -9,9 +9,11 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.app.dto.GetPlaceListDTO;
 import org.jeecg.modules.app.dto.SearchDTO;
 import org.jeecg.modules.app.service.IAppHomeService;
-import org.jeecg.modules.app.service.IDetailService;
 import org.jeecg.modules.app.service.IUserService;
-import org.jeecg.modules.app.vo.*;
+import org.jeecg.modules.app.vo.HomeVO;
+import org.jeecg.modules.app.vo.MsgInfoVO;
+import org.jeecg.modules.app.vo.MsgVO;
+import org.jeecg.modules.app.vo.PlaceVO;
 import org.jeecg.modules.system.app.entity.AppSearchHot;
 import org.springframework.web.bind.annotation.*;
 
@@ -27,8 +29,6 @@ public class AppHomeController {
     private IAppHomeService appHomeService;
     @Resource
     private IUserService userService;
-    @Resource
-    private IDetailService detailService;
 
     @GetMapping("/homeInfo")
     @Operation(summary = "首页基础数据查询")
@@ -98,42 +98,4 @@ public class AppHomeController {
         return Result.ok(appHomeService.getHotSearch());
     }
 
-    /**
-     * @Author SheepHy
-     * @Description 门店详情信息查询
-     * @Date 19:41 2025/7/7
-     * @Param id 门店id
-     * @return PlaceInfoVO {@link PlaceInfoVO}
-     **/
-    @GetMapping("/getPlaceInfo")
-    @Operation(summary = "门店详情信息查询 ")
-    public Result<PlaceInfoVO> getPlaceInfo(@RequestParam @Schema(description="门店ID") String id){
-        return Result.ok(detailService.getPlaceInfo(id));
-    }
-
-    /**
-     * @Author SheepHy
-     * @Description 课程详情
-     * @Date 13:36 2025/7/8
-     * @Param id 课程id
-     * @return CourseInfoVO {@link CourseInfoVO}
-     **/
-    @GetMapping("/getCourseInfo")
-    @Operation(summary = "课程详情")
-    public Result<CourseInfoVO> getCourseInfo(@RequestParam @Schema(description="课程ID")String id, @RequestParam double latitude,@RequestParam double longitude){
-        return Result.ok(detailService.getCourseInfo(id, latitude, longitude));
-    }
-
-    /**
-     * @Author SheepHy
-     * @Description 根据课程类型查询课程列表
-     * @Date 9:52 2025/7/9
-     * @Param type 课程类型
-     * @return List<PlaceInfoVO.CourseInfoVO>
-     **/
-    @GetMapping("/courseInfoVOList")
-    @Operation(summary = "根据课程类型查询课程列表")
-    public Result<List<PlaceInfoVO.CourseInfoVO>> courseInfoVOList(@RequestParam @Schema(description="课程类型")String type, @RequestParam @Schema(description="课程ID")String id){
-        return Result.ok(detailService.courseInfoVOList(type, id));
-    }
 }

+ 3 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/controller/AppUserController.java

@@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.RedisUtil;
 import org.jeecg.modules.app.service.IUserService;
 import org.jeecg.modules.app.vo.LoginUserVO;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -21,6 +22,8 @@ import javax.annotation.Resource;
 public class AppUserController {
     @Resource
     private IUserService userService;
+    @Resource
+    private RedisUtil redisUtil;
 
 
     /**

+ 1 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/IDetailService.java

@@ -35,7 +35,7 @@ public interface IDetailService {
     
     /** 
      * @Author SheepHy
-     * @Description //TODO 
+     * @Description 根据类目类型查询体育馆场地空闲时间段
      * @Date 10:14 2025/7/9
      * @Param 
      * @return 

+ 18 - 7
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/UserServiceImpl.java

@@ -7,11 +7,15 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.extern.log4j.Log4j2;
 import me.chanjar.weixin.common.error.WxErrorException;
 import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.mgt.SecurityManager;
+import org.apache.shiro.subject.Subject;
+import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.util.JwtUtil;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.RedisUtil;
 import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.config.shiro.JwtToken;
 import org.jeecg.modules.app.service.IUserService;
 import org.jeecg.modules.app.vo.LoginUserVO;
 import org.jeecg.modules.app.vo.MsgInfoVO;
@@ -48,6 +52,8 @@ public class UserServiceImpl implements IUserService {
     @Resource
     private FamilyMembersMapper familyMembersMapper;
     @Resource
+    private SecurityManager securityManager;
+    @Resource
     private RedisUtil redisUtil;
 
     @Override
@@ -119,14 +125,19 @@ public class UserServiceImpl implements IUserService {
 
 
     private LoginUserVO generateLoginUserVO(SysUser user) {
-        String userAccount = user.getUsername();
-        String userPassword = user.getPassword();
-        // 1.生成token
-        String token = JwtUtil.sign(userAccount, userPassword);
+        String token = JwtUtil.sign(user.getUsername(), user.getPassword());
         // 设置token缓存有效时间
-        redisUtil.set(PREFIX_USER_TOKEN + token, token);
-        redisUtil.expire(PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
-        return new LoginUserVO().setToken(token)
+        redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
+        redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
+        // 创建 JwtToken 并登录 Subject
+        JwtToken jwtToken = new JwtToken(token);
+        Subject subject = new Subject.Builder(securityManager).buildSubject();
+        subject.login(jwtToken); // 触发 Shiro 登录流程
+        // 确保 LoginUser 可被后续获取
+        LoginUser loginUser = new LoginUser();
+        BeanUtils.copyProperties(loginUser, user);
+        return new LoginUserVO()
+                .setToken(token)
                 .setId(user.getId())
                 .setUserName(user.getUsername())
                 .setUserAvatar(user.getAvatar());

+ 16 - 16
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/vo/PlaceInfoVO.java

@@ -59,22 +59,22 @@ public class PlaceInfoVO {
         @Schema(description = "售价")
         private BigDecimal sellingPrice;
     }
-//    @Data
-//    @Accessors(chain = true)
-//    @EqualsAndHashCode(callSuper = false)
-//    @Schema(description="场地简约返回参数-体育馆")
-//    public static class PlaceInfoMsgVO{
-//        @Schema(description = "场地名称")
-//        private String name;
-//        @Schema(description = "销售数量")
-//        private int sales;
-//        @Schema(description = "类目")
-//        private List<String> category;
-//        @Schema(description = "原价")
-//        private BigDecimal originalPrice;
-//        @Schema(description = "售价")
-//        private BigDecimal sellingPrice;
-//    }
+    @Data
+    @Accessors(chain = true)
+    @EqualsAndHashCode(callSuper = false)
+    @Schema(description="场地简约返回参数-体育馆")
+    public static class PlaceInfoGymMsgVO{
+        @Schema(description = "场地名称")
+        private String name;
+        @Schema(description = "销售数量")
+        private int sales;
+        @Schema(description = "类目")
+        private List<String> category;
+        @Schema(description = "原价")
+        private BigDecimal originalPrice;
+        @Schema(description = "售价")
+        private BigDecimal sellingPrice;
+    }
     @Data
     @Accessors(chain = true)
     @EqualsAndHashCode(callSuper = false)