diff --git a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java index 7720153..809d817 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java @@ -8,6 +8,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.context.annotation.Bean; /** @@ -16,6 +17,7 @@ import org.springframework.context.annotation.Bean; * @author ruoyi */ @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) +@ServletComponentScan public class RuoYiApplication { public static void main(String[] args) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/LoginFilter.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/LoginFilter.java new file mode 100644 index 0000000..987496f --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/LoginFilter.java @@ -0,0 +1,55 @@ +package com.ruoyi.web.controller.tool; + +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.system.domain.TDoctor; +import com.ruoyi.system.service.ITDoctorService; +import com.ruoyi.system.service.impl.UserTokenService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.annotation.Order; + +import javax.annotation.Resource; +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.util.Objects; + +@Order(1) +@WebFilter(filterName = "loginFilter", urlPatterns = "/api/app/*") +public class LoginFilter implements Filter { + private static final Logger logger = LoggerFactory.getLogger(LoginFilter.class); + @Autowired + private UserTokenService userTokenService; + + @Resource + private ITDoctorService tDoctorService; + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + Filter.super.init(filterConfig); + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + String currentUrl = ((HttpServletRequest) servletRequest).getServletPath(); + if (!currentUrl.equals("/api/app/hospital/list")) { + LoginUser loginUser = userTokenService.getLoginUser((HttpServletRequest) servletRequest); + SysUser user = loginUser.getUser(); + TDoctor tDoctor = tDoctorService.selectTDoctorByPhone(user.getPhonenumber()); + if (Objects.isNull(tDoctor) || "2".equals(tDoctor.getDelFlag())) { + logger.info("doctor has been deleted , doctor info :{}", tDoctor); + throw new ServiceException("用户已被删除"); + } + } + filterChain.doFilter(servletRequest, servletResponse); + } + + @Override + public void destroy() { + Filter.super.destroy(); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ITDoctorService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITDoctorService.java index fb47d16..af5316e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ITDoctorService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITDoctorService.java @@ -71,4 +71,6 @@ public interface ITDoctorService * @return 医生信息 */ public AppDoctorResp selectAppDoctorDetailById(Long id); + + public TDoctor selectTDoctorByPhone(String phone); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDoctorServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDoctorServiceImpl.java index bd1583e..8689fd4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDoctorServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDoctorServiceImpl.java @@ -134,4 +134,9 @@ public class TDoctorServiceImpl implements ITDoctorService public AppDoctorResp selectAppDoctorDetailById(Long id) { return tDoctorMapper.selectAppDoctorDetailById(id); } + + @Override + public TDoctor selectTDoctorByPhone(String phone) { + return tDoctorMapper.selectTDoctorByPhone(phone); + } }