Selaa lähdekoodia

移动端api拦截器,

yangfeng 1 vuosi sitten
vanhempi
commit
af89364281

+ 1 - 0
core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -149,6 +149,7 @@ public class ShiroConfig {
         //错误路径排除
         filterChainDefinitionMap.put("/error", "anon");
         // update-end--author:liusq Date:20230522 for:[issues/4829]访问不存在的url时会提示Token失效,请重新登录呢
+        filterChainDefinitionMap.put("/api/v1/**", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<String, Filter>(1);

+ 0 - 79
system/system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java

@@ -24,7 +24,6 @@ import org.jeecg.config.JeecgBaseConfig;
 import org.jeecg.modules.base.service.BaseCommonService;
 import org.jeecg.modules.system.entity.SysDepart;
 import org.jeecg.modules.system.entity.SysRoleIndex;
-import org.jeecg.modules.system.entity.SysTenant;
 import org.jeecg.modules.system.entity.SysUser;
 import org.jeecg.modules.system.enums.UserType;
 import org.jeecg.modules.system.model.SysLoginModel;
@@ -579,84 +578,6 @@ public class LoginController {
         return res;
     }
 
-    /**
-     * app登录
-     *
-     * @param sysLoginModel
-     * @return
-     * @throws Exception
-     */
-    @RequestMapping(value = "/mLogin", method = RequestMethod.POST)
-    public Result<JSONObject> mLogin(@RequestBody SysLoginModel sysLoginModel) throws Exception {
-        Result<JSONObject> result = new Result<JSONObject>();
-        String username = sysLoginModel.getUsername();
-        String password = sysLoginModel.getPassword();
-        JSONObject obj = new JSONObject();
-
-        //update-begin-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户
-        if (isLoginFailOvertimes(username)) {
-            return result.error500("该用户登录失败次数过多,请于10分钟后再次登录!");
-        }
-        //update-end-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户
-        //1. 校验用户是否有效
-        SysUser sysUser = sysUserService.getUserByName(username);
-        result = sysUserService.checkUserIsEffective(sysUser);
-        if (!result.isSuccess()) {
-            return result;
-        }
-
-        //2. 校验用户名或密码是否正确
-        String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
-        String syspassword = sysUser.getPassword();
-        if (!syspassword.equals(userpassword)) {
-            //update-begin-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户
-            addLoginFailOvertimes(username);
-            //update-end-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户
-            result.error500("用户名或密码错误");
-            return result;
-        }
-
-        //3.设置登录部门
-        String orgCode = sysUser.getOrgCode();
-        if (oConvertUtils.isEmpty(orgCode)) {
-            //如果当前用户无选择部门 查看部门关联信息
-            List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
-            //update-begin-author:taoyan date:20220117 for: JTC-1068【app】新建用户,没有设置部门及角色,点击登录提示暂未归属部,一直在登录页面 使用手机号登录 可正常
-            if (departs == null || departs.size() == 0) {
-				/*result.error500("用户暂未归属部门,不可登录!");
-				return result;*/
-            } else {
-                orgCode = departs.get(0).getOrgCode();
-                sysUser.setOrgCode(orgCode);
-                this.sysUserService.updateUserDepart(username, orgCode, null);
-            }
-            //update-end-author:taoyan date:20220117 for: JTC-1068【app】新建用户,没有设置部门及角色,点击登录提示暂未归属部,一直在登录页面 使用手机号登录 可正常
-        }
-
-        //4. 设置登录租户
-        Result<JSONObject> loginTenantError = sysUserService.setLoginTenant(sysUser, obj, username, result);
-        if (loginTenantError != null) {
-            return loginTenantError;
-        }
-
-        //5. 设置登录用户信息
-        obj.put("userInfo", sysUser);
-
-        //6. 生成token
-        String token = JwtUtil.sign(username, syspassword);
-        // 设置超时时间
-        redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
-        redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
-
-        //token 信息
-        obj.put("token", token);
-        result.setResult(obj);
-        result.setSuccess(true);
-        result.setCode(200);
-        baseCommonService.addLog("用户名: " + username + ",登录成功[移动端]!", CommonConstant.LOG_TYPE_1, null);
-        return result;
-    }
-
     /**
      * 图形验证码
      *

+ 15 - 0
web/src/main/java/com/ynfy/app/api/v1/annoation/IgnoreAuth.java

@@ -0,0 +1,15 @@
+package com.ynfy.app.api.v1.annoation;
+
+
+import java.lang.annotation.*;
+
+/**
+ * 忽略Token验证
+ *
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface IgnoreAuth {
+
+}

+ 155 - 0
web/src/main/java/com/ynfy/app/api/v1/controller/ApiAuthController.java

@@ -0,0 +1,155 @@
+package com.ynfy.app.api.v1.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.ynfy.app.api.v1.annoation.IgnoreAuth;
+import io.swagger.annotations.Api;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.system.util.JwtUtil;
+import org.jeecg.common.util.PasswordUtil;
+import org.jeecg.common.util.RedisUtil;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.base.service.BaseCommonService;
+import org.jeecg.modules.system.entity.SysDepart;
+import org.jeecg.modules.system.entity.SysUser;
+import org.jeecg.modules.system.model.SysLoginModel;
+import org.jeecg.modules.system.service.ISysDepartService;
+import org.jeecg.modules.system.service.ISysUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Api(tags = "API登录授权接口")
+@RestController
+@RequestMapping("/api/v1/auth")
+public class ApiAuthController {
+
+    @Autowired
+    private ISysUserService sysUserService;
+    @Autowired
+    private RedisUtil redisUtil;
+    @Autowired
+    private ISysDepartService sysDepartService;
+    @Resource
+    private BaseCommonService baseCommonService;
+
+    /**
+     * app登录
+     *
+     * @param sysLoginModel
+     * @return
+     * @throws Exception
+     */
+    @IgnoreAuth
+    @RequestMapping(value = "/login", method = RequestMethod.POST)
+    public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel) throws Exception {
+        Result<JSONObject> result = new Result<JSONObject>();
+        String username = sysLoginModel.getUsername();
+        String password = sysLoginModel.getPassword();
+        JSONObject obj = new JSONObject();
+
+        //update-begin-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户
+        if (isLoginFailOvertimes(username)) {
+            return result.error500("该用户登录失败次数过多,请于10分钟后再次登录!");
+        }
+        //update-end-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户
+        //1. 校验用户是否有效
+        SysUser sysUser = sysUserService.getUserByName(username);
+        result = sysUserService.checkUserIsEffective(sysUser);
+        if (!result.isSuccess()) {
+            return result;
+        }
+
+        //2. 校验用户名或密码是否正确
+        String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
+        String syspassword = sysUser.getPassword();
+        if (!syspassword.equals(userpassword)) {
+            //update-begin-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户
+            addLoginFailOvertimes(username);
+            //update-end-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户
+            result.error500("用户名或密码错误");
+            return result;
+        }
+
+        //3.设置登录部门
+        String orgCode = sysUser.getOrgCode();
+        if (oConvertUtils.isEmpty(orgCode)) {
+            //如果当前用户无选择部门 查看部门关联信息
+            List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
+            //update-begin-author:taoyan date:20220117 for: JTC-1068【app】新建用户,没有设置部门及角色,点击登录提示暂未归属部,一直在登录页面 使用手机号登录 可正常
+            if (departs == null || departs.size() == 0) {
+				/*result.error500("用户暂未归属部门,不可登录!");
+				return result;*/
+            } else {
+                orgCode = departs.get(0).getOrgCode();
+                sysUser.setOrgCode(orgCode);
+                this.sysUserService.updateUserDepart(username, orgCode, null);
+            }
+            //update-end-author:taoyan date:20220117 for: JTC-1068【app】新建用户,没有设置部门及角色,点击登录提示暂未归属部,一直在登录页面 使用手机号登录 可正常
+        }
+
+        //4. 设置登录租户
+        Result<JSONObject> loginTenantError = sysUserService.setLoginTenant(sysUser, obj, username, result);
+        if (loginTenantError != null) {
+            return loginTenantError;
+        }
+
+        //5. 设置登录用户信息
+        obj.put("userInfo", sysUser);
+
+        //6. 生成token
+        String token = JwtUtil.sign(username, syspassword);
+        // 设置超时时间
+        redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
+        redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
+
+        //token 信息
+        obj.put("token", token);
+        result.setResult(obj);
+        result.setSuccess(true);
+        result.setCode(200);
+        baseCommonService.addLog("用户名: " + username + ",登录成功[移动端]!", CommonConstant.LOG_TYPE_1, null);
+        return result;
+    }
+
+    /**
+     * 登录失败超出次数5 返回true
+     *
+     * @param username
+     * @return
+     */
+    private boolean isLoginFailOvertimes(String username) {
+        String key = CommonConstant.LOGIN_FAIL + username;
+        Object failTime = redisUtil.get(key);
+        if (failTime != null) {
+            Integer val = Integer.parseInt(failTime.toString());
+            if (val > 5) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * 记录登录失败次数
+     *
+     * @param username
+     */
+    private void addLoginFailOvertimes(String username) {
+        String key = CommonConstant.LOGIN_FAIL + username;
+        Object failTime = redisUtil.get(key);
+        Integer val = 0;
+        if (failTime != null) {
+            val = Integer.parseInt(failTime.toString());
+        }
+        // 10分钟
+        redisUtil.set(key, ++val, 10);
+    }
+
+}

+ 212 - 0
web/src/main/java/com/ynfy/app/api/v1/controller/ApiExamController.java

@@ -0,0 +1,212 @@
+package com.ynfy.app.api.v1.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ynfy.buss.exam.exam.dto.ExamSubmitDTO;
+import com.ynfy.buss.exam.exam.dto.QuestionTypeCountDTO;
+import com.ynfy.buss.exam.exam.entity.Exam;
+import com.ynfy.buss.exam.exam.service.IExamService;
+import com.ynfy.buss.exam.paper.enmus.JoinType;
+import com.ynfy.buss.exam.paper.entity.Paper;
+import com.ynfy.buss.exam.paperrulegroup.service.IPaperRuleGroupService;
+import com.ynfy.buss.exam.question.enums.QuestionType;
+import com.ynfy.buss.exam.userexam.entity.UserExam;
+import com.ynfy.buss.exam.userexam.service.IUserExamService;
+import com.ynfy.buss.exam.userexamresult.entity.UserExamResult;
+import com.ynfy.buss.exam.userexamresult.service.IUserExamResultService;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+import java.util.Objects;
+
+@Slf4j
+@RestController
+@RequestMapping("/api/v1/exam")
+public class ApiExamController {
+
+    @Autowired
+    public IExamService examService;
+
+    @Autowired
+    private IUserExamService userExamService;
+
+    @Autowired
+    private IPaperRuleGroupService paperRuleGroupService;
+
+    @Autowired
+    private IUserExamResultService userExamResultService;
+
+    /**
+     * 获取考试列表
+     *
+     * @param exam
+     * @param pageNo
+     * @param pageSize
+     * @return
+     */
+    @PostMapping("/list")
+    public Result<IPage<Exam>> list(Exam exam, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        Page<Exam> page = new Page<>(pageNo, pageSize);
+        IPage<Exam> pageList = examService.selectExamList(page, exam);
+        return Result.OK(pageList);
+    }
+
+    @GetMapping(value = "/queryById")
+    public Result<Exam> queryById(@RequestParam(name = "id", required = true) String id) {
+        Exam exam = examService.detail(id);
+        if (Objects.isNull(exam)) {
+            return Result.error("考试不存在");
+        }
+        Paper paper = exam.getPaper();
+        if (!Objects.isNull(paper)) {
+            paper.setJoinType_dictText(JoinType.getByCode(paper.getJoinType()).getValue());
+        }
+        List<QuestionTypeCountDTO> dtoList = paperRuleGroupService.sumQuestionCount(exam.getPaperId());
+        if (!CollectionUtils.isEmpty(dtoList)) {
+            dtoList.stream().forEach(dto -> dto.setQuestionTypeName(QuestionType.getByCode(dto.getQuestionType()).getValue()));
+            exam.setQuestionTypeCountList(dtoList);
+        }
+        return Result.OK(exam);
+    }
+
+
+    @GetMapping(value = "/createExam")
+    public Result<?> createExam(@RequestParam(name = "examId") String examId) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        return Result.ok(examService.createExam(user.getId(), examId));
+    }
+
+    @GetMapping(value = "/listExamIn")
+    public Result<?> listExamIn() {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        // 校验是否有正在考试的试卷
+        UserExam userExam = userExamService.listExamIn(user.getId());
+        if (!Objects.isNull(userExam)) {
+            return Result.ok(userExam);
+        }
+        return Result.OK();
+    }
+
+    /**
+     * 考试详情,包括答题卡,试题(不包含正确答案)
+     *
+     * @return
+     */
+    @ApiOperation(value = "考试-考试详情")
+    @GetMapping(value = "/examDetail")
+    public Result<?> examDetail(@RequestParam(name = "userExamId") String userExamId) {
+        return Result.ok(examService.examDetail(userExamId));
+    }
+
+    /**
+     * 交卷
+     *
+     * @return
+     */
+    @ApiOperation(value = "考试-交卷")
+    @PostMapping(value = "/submitExam")
+    public Result<?> submitExam(@RequestBody ExamSubmitDTO dto) {
+        examService.submitExam(dto);
+        return Result.ok("提交试卷成功!");
+    }
+
+
+    /**
+     * 缓存考试答案,用于定时任务强制交卷
+     *
+     * @return
+     */
+    @PostMapping(value = "/cacheExamAnswer")
+    public Result<?> cacheExamAnswer(@RequestBody ExamSubmitDTO dto) {
+        examService.cacheExamAnswer(dto);
+        return Result.ok();
+    }
+
+
+    /**
+     * 获取缓存的考试答案
+     *
+     * @return
+     */
+    @GetMapping(value = "/getCacheAnswer")
+    public Result<?> getCacheAnswer(@RequestParam(name = "userExamId") String userExamId) {
+        return Result.ok(examService.getCacheAnswer(userExamId));
+    }
+
+    /**
+     * 用户考试成绩详情,包括答题卡,试题(包含正确答案)
+     *
+     * @param userExamId
+     * @return
+     */
+    @ApiOperation(value = "考试-用户考试成绩详情")
+    @GetMapping(value = "/userExamResultDetail")
+    public Result<?> userExamResultDetail(@RequestParam(name = "userExamId") String userExamId) {
+        return Result.ok(examService.userExamResultDetail(userExamId));
+    }
+
+    @GetMapping(value = "/userExamResult/list")
+    public Result<IPage<UserExamResult>> queryPageList(UserExamResult userExamResult,
+                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        Page<UserExamResult> page = new Page<UserExamResult>(pageNo, pageSize);
+        IPage<UserExamResult> pageList = userExamResultService.selectPageList(page, userExamResult);
+        return Result.OK(pageList);
+    }
+
+    @GetMapping(value = "/userExamDetail/list")
+    public Result<IPage<UserExam>> queryPageList(UserExam userExam,
+                                                 @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                 HttpServletRequest req) {
+        Page<UserExam> page = new Page<UserExam>(pageNo, pageSize);
+        IPage<UserExam> pageList = userExamService.selectPageList(page, userExam);
+        return Result.OK(pageList);
+    }
+
+    /**
+     * 检查是否达到考试限制次数
+     *
+     * @param examId
+     * @return
+     */
+    @GetMapping(value = "/checkToLimit")
+    public Result<?> checkToLimit(@RequestParam(name = "examId") String examId) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        return Result.ok(examService.checkToLimit(user.getId(), examId));
+    }
+
+    /**
+     * 检查是否有考试记录
+     *
+     * @param examId
+     * @return
+     */
+    @GetMapping(value = "/examRecordExist")
+    public Result<?> examRecordExist(@RequestParam(name = "examId") String examId) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        return Result.ok(examService.examRecordExist(user.getId(), examId));
+    }
+
+    /**
+     * 获取用户考试成绩
+     *
+     * @param examId
+     * @return
+     */
+    @GetMapping(value = "/examScore")
+    public Result<?> examScore(@RequestParam(name = "examId") String examId) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        return Result.ok(userExamResultService.examScore(user.getId(), examId));
+    }
+
+}

+ 85 - 0
web/src/main/java/com/ynfy/app/api/v1/interceptor/AuthorizationInterceptor.java

@@ -0,0 +1,85 @@
+package com.ynfy.app.api.v1.interceptor;
+
+import com.auth0.jwt.exceptions.TokenExpiredException;
+import com.ynfy.app.api.v1.annoation.IgnoreAuth;
+import com.ynfy.app.api.v1.util.TokenUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.common.system.util.JwtUtil;
+import org.jeecg.modules.system.entity.SysUser;
+import org.jeecg.modules.system.service.ISysUserService;
+import org.springframework.stereotype.Component;
+import org.springframework.web.method.HandlerMethod;
+import org.springframework.web.servlet.HandlerInterceptor;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * 权限(Token)验证
+ */
+@Component
+public class AuthorizationInterceptor implements HandlerInterceptor {
+
+    @Resource
+    private ISysUserService sysUserService;
+
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+
+        //支持跨域请求
+        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
+        response.setHeader("Access-Control-Allow-Credentials", "true");
+        response.setHeader("Access-Control-Allow-Headers", "x-requested-with,X-Exam-Token,X-URL-PATH,content-type");
+        response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
+
+        IgnoreAuth annotation;
+        if (handler instanceof HandlerMethod) {
+            annotation = ((HandlerMethod) handler).getMethodAnnotation(IgnoreAuth.class);
+        } else {
+            return true;
+        }
+
+        //如果有@IgnoreAuth注解,则不验证token
+        if (annotation != null) {
+            return true;
+        }
+
+        //获取token
+        String token = TokenUtil.getToken(request);
+        String userName = TokenUtil.getUserName(token);
+
+        if (StringUtils.isEmpty(userName)) {
+            throw new JeecgBootException("token错误");
+        } else {
+            SysUser user = sysUserService.getUserByName(userName);
+            if (user == null) {
+                throw new JeecgBootException("用户不存在!");
+            } else {
+                try {
+                    JwtUtil.verify(token, "userId", userName);
+                } catch (TokenExpiredException var6) {
+                    throw new JeecgBootException("token失效,请重新登录");
+                } catch (Exception e) {
+                    throw new JeecgBootException("token认证失败");
+                }
+            }
+        }
+        return true;
+    }
+
+    //方法执行后
+    @Override
+    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
+
+    }
+
+    //页面渲染前
+    @Override
+    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
+
+    }
+
+}

+ 53 - 0
web/src/main/java/com/ynfy/app/api/v1/util/TokenUtil.java

@@ -0,0 +1,53 @@
+package com.ynfy.app.api.v1.util;
+
+import org.apache.commons.lang3.StringUtils;
+import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.common.system.util.JwtUtil;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * token工具
+ */
+public class TokenUtil {
+
+    public static final String LOGIN_TOKEN_KEY = "X-Exam-Token";
+
+
+    /**
+     * 获取token
+     *
+     * @param request
+     * @return
+     */
+    public static String getToken(HttpServletRequest request) {
+        //从header中获取token
+        String token = request.getHeader(LOGIN_TOKEN_KEY);
+        //如果header中不存在token,则从参数中获取token
+        if (StringUtils.isBlank(token)) {
+            token = request.getParameter(LOGIN_TOKEN_KEY);
+        }
+        //token为空
+        if (StringUtils.isBlank(token)) {
+            throw new JeecgBootException("请先登录");
+        }
+        return token;
+    }
+
+
+    /**
+     * 获取用户名
+     *
+     * @param token
+     * @return
+     */
+    public static String getUserName(String token) {
+        //token为空
+        if (StringUtils.isBlank(token)) {
+            throw new JeecgBootException("请先登录");
+        }
+
+        return JwtUtil.getUsername(token);
+    }
+
+}

+ 1 - 1
web/src/main/java/com/ynfy/buss/exam/exam/mapper/xml/ExamMapper.xml

@@ -88,7 +88,7 @@
             WHERE
                 open_type = 1
             <choose>
-                <when test="user.orgCode!=null and user.orgCode!=''">
+                <when test="user!=null and user.orgCode!=null and user.orgCode!=''">
             UNION
             SELECT
                     *

+ 2 - 2
web/src/main/java/com/ynfy/buss/exam/exam/service/impl/ExamServiceImpl.java

@@ -115,10 +115,10 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
     @Override
     public IPage<Exam> selectExamList(IPage<Exam> page, Exam exam) {
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-        if (StringUtils.isNotBlank(exam.getTitle())) {
+        if (!Objects.isNull(exam) && StringUtils.isNotBlank(exam.getTitle())) {
             exam.setTitle(exam.getTitle().replace("*", ""));
         }
-        if (StringUtils.isNotBlank(user.getOrgCode())) {
+        if (!Objects.isNull(user) && StringUtils.isNotBlank(user.getOrgCode())) {
             SysDepart depart = sysDepartService.queryByOrgCode(user.getOrgCode());
             if (!Objects.isNull(depart)) {
                 user.setOrgCode(depart.getId());

+ 18 - 14
core/src/main/java/org/jeecg/config/WebMvcConfiguration.java → web/src/main/java/com/ynfy/config/WebMvcConfiguration.java

@@ -1,4 +1,4 @@
-package org.jeecg.config;
+package com.ynfy.config;
 
 import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -10,7 +10,10 @@ import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
+import com.ynfy.app.api.v1.interceptor.AuthorizationInterceptor;
 import io.micrometer.prometheus.PrometheusMeterRegistry;
+import org.jeecg.config.CorsFilterCondition;
+import org.jeecg.config.JeecgBaseConfig;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -25,10 +28,7 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
 import org.springframework.web.cors.CorsConfiguration;
 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
 import org.springframework.web.filter.CorsFilter;
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration;
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.config.annotation.*;
 
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
@@ -46,6 +46,8 @@ import java.util.List;
  */
 @Configuration
 public class WebMvcConfiguration implements WebMvcConfigurer {
+    @Resource
+    private AuthorizationInterceptor authorizationInterceptor;
 
     @Resource
     JeecgBaseConfig jeecgBaseConfig;
@@ -146,13 +148,15 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
         return () -> meterRegistryPostProcessor.postProcessAfterInitialization(prometheusMeterRegistry, "");
     }
 
-//    /**
-//     * 注册拦截器【拦截器拦截参数,自动切换数据源——后期实现多租户切换数据源功能】
-//     * @param registry
-//     */
-//    @Override
-//    public void addInterceptors(InterceptorRegistry registry) {
-//        registry.addInterceptor(new DynamicDatasourceInterceptor()).addPathPatterns("/test/dynamic/**");
-//    }
-
+    /**
+     * 拦截微信接口
+     *
+     * @param registry
+     */
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        //注册自定义拦截器,添加拦截路径和排除拦截路径
+        registry.addInterceptor(authorizationInterceptor)
+                .addPathPatterns("/api/v1/**");
+    }
 }