24282 2 rokov pred
rodič
commit
eeac0b417a
34 zmenil súbory, kde vykonal 716 pridanie a 50 odobranie
  1. 39 0
      hx-socket/pom.xml
  2. 17 0
      hx-socket/src/main/java/com/fjhx/socket/config/WebSocketConfig.java
  3. 37 0
      hx-socket/src/main/java/com/fjhx/socket/entity/MessageEntity.java
  4. 22 0
      hx-socket/src/main/java/com/fjhx/socket/event/WebSocketOnCloseEvent.java
  5. 20 0
      hx-socket/src/main/java/com/fjhx/socket/event/WebSocketOnErrorEvent.java
  6. 25 0
      hx-socket/src/main/java/com/fjhx/socket/event/WebSocketOnMessageEvent.java
  7. 22 0
      hx-socket/src/main/java/com/fjhx/socket/event/WebSocketOnOpenEvent.java
  8. 27 0
      hx-socket/src/main/java/com/fjhx/socket/event/WebSocketSendFailEvent.java
  9. 26 0
      hx-socket/src/main/java/com/fjhx/socket/event/WebSocketSendSuccessEvent.java
  10. 24 0
      hx-socket/src/main/java/com/fjhx/socket/event/WebSocketUserOfflineEvent.java
  11. 214 0
      hx-socket/src/main/java/com/fjhx/socket/service/WebSocketServer.java
  12. 14 0
      pom.xml
  13. 10 0
      ruoyi-admin/pom.xml
  14. 3 1
      ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java
  15. 1 1
      ruoyi-admin/src/main/resources/application.yml
  16. 6 0
      ruoyi-common/pom.xml
  17. 19 0
      ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseIdPo.java
  18. 38 0
      ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BasePo.java
  19. 91 0
      ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseSelectDto.java
  20. 2 1
      ruoyi-common/src/main/java/com/ruoyi/common/core/service/BaseService.java
  21. 11 0
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResponseAdvice.java
  22. 1 1
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
  23. 25 27
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java
  24. 2 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
  25. 2 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
  26. 2 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
  27. 2 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
  28. 2 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysLogininforService.java
  29. 2 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java
  30. 2 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java
  31. 2 1
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOperLogService.java
  32. 2 1
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java
  33. 2 1
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java
  34. 2 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java

+ 39 - 0
hx-socket/pom.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.ruoyi</groupId>
+        <artifactId>ruoyi</artifactId>
+        <version>3.8.5</version>
+    </parent>
+
+    <artifactId>hx-socket</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-websocket</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.ruoyi</groupId>
+            <artifactId>ruoyi-common</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.ruoyi</groupId>
+            <artifactId>ruoyi-framework</artifactId>
+        </dependency>
+
+    </dependencies>
+
+</project>

+ 17 - 0
hx-socket/src/main/java/com/fjhx/socket/config/WebSocketConfig.java

@@ -0,0 +1,17 @@
+package com.fjhx.socket.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.config.annotation.EnableWebSocket;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+@Configuration
+@EnableWebSocket
+public class WebSocketConfig {
+
+    @Bean
+    public ServerEndpointExporter serverEndpointExporter() {
+        return new ServerEndpointExporter();
+    }
+
+}

+ 37 - 0
hx-socket/src/main/java/com/fjhx/socket/entity/MessageEntity.java

@@ -0,0 +1,37 @@
+package com.fjhx.socket.entity;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class MessageEntity {
+
+    /**
+     * 用户id
+     */
+    private Long userId;
+
+    /**
+     * 会话id
+     */
+    private Long sessionId;
+
+    /**
+     * 消息创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 类型
+     *
+     * @remark -1:websocket链接失败  其他状态根据业务自定义
+     */
+    private Integer type;
+
+    /**
+     * 消息主体
+     */
+    private Object data;
+
+}

+ 22 - 0
hx-socket/src/main/java/com/fjhx/socket/event/WebSocketOnCloseEvent.java

@@ -0,0 +1,22 @@
+package com.fjhx.socket.event;
+
+import com.fjhx.socket.service.WebSocketServer;
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * webStock关闭连接事件
+ */
+@Getter
+public class WebSocketOnCloseEvent extends ApplicationEvent {
+
+    public WebSocketOnCloseEvent(Object source) {
+        super(source);
+    }
+
+    @Override
+    public WebSocketServer getSource() {
+        return (WebSocketServer) super.getSource();
+    }
+
+}

+ 20 - 0
hx-socket/src/main/java/com/fjhx/socket/event/WebSocketOnErrorEvent.java

@@ -0,0 +1,20 @@
+package com.fjhx.socket.event;
+
+import com.fjhx.socket.service.WebSocketServer;
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * webStock发送异常
+ */
+@Getter
+public class WebSocketOnErrorEvent extends ApplicationEvent {
+
+    private final Throwable throwable;
+
+    public WebSocketOnErrorEvent(WebSocketServer source, Throwable throwable) {
+        super(source);
+        this.throwable = throwable;
+    }
+
+}

+ 25 - 0
hx-socket/src/main/java/com/fjhx/socket/event/WebSocketOnMessageEvent.java

@@ -0,0 +1,25 @@
+package com.fjhx.socket.event;
+
+import com.fjhx.socket.service.WebSocketServer;
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * webStock接收消息事件
+ */
+@Getter
+public class WebSocketOnMessageEvent extends ApplicationEvent {
+
+    private final String message;
+
+    public WebSocketOnMessageEvent(WebSocketServer source, String message) {
+        super(source);
+        this.message = message;
+    }
+
+    @Override
+    public WebSocketServer getSource() {
+        return (WebSocketServer) super.getSource();
+    }
+
+}

+ 22 - 0
hx-socket/src/main/java/com/fjhx/socket/event/WebSocketOnOpenEvent.java

@@ -0,0 +1,22 @@
+package com.fjhx.socket.event;
+
+import com.fjhx.socket.service.WebSocketServer;
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * webStock建立连接事件
+ */
+@Getter
+public class WebSocketOnOpenEvent extends ApplicationEvent {
+
+    public WebSocketOnOpenEvent(WebSocketServer source) {
+        super(source);
+    }
+
+    @Override
+    public WebSocketServer getSource() {
+        return (WebSocketServer) super.getSource();
+    }
+
+}

+ 27 - 0
hx-socket/src/main/java/com/fjhx/socket/event/WebSocketSendFailEvent.java

@@ -0,0 +1,27 @@
+package com.fjhx.socket.event;
+
+
+import com.fjhx.socket.service.WebSocketServer;
+import com.fjhx.socket.entity.MessageEntity;
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * webStock推送消息失败事件
+ */
+@Getter
+public class WebSocketSendFailEvent extends ApplicationEvent {
+
+    private final MessageEntity messageEntity;
+
+    public WebSocketSendFailEvent(WebSocketServer source, MessageEntity messageEntity) {
+        super(source);
+        this.messageEntity = messageEntity;
+    }
+
+    @Override
+    public WebSocketServer getSource() {
+        return (WebSocketServer)super.getSource();
+    }
+
+}

+ 26 - 0
hx-socket/src/main/java/com/fjhx/socket/event/WebSocketSendSuccessEvent.java

@@ -0,0 +1,26 @@
+package com.fjhx.socket.event;
+
+import com.fjhx.socket.entity.MessageEntity;
+import com.fjhx.socket.service.WebSocketServer;
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * webStock推送消息成功事件
+ */
+@Getter
+public class WebSocketSendSuccessEvent extends ApplicationEvent {
+
+    private final MessageEntity messageEntity;
+
+    public WebSocketSendSuccessEvent(WebSocketServer source, MessageEntity messageEntity) {
+        super(source);
+        this.messageEntity = messageEntity;
+    }
+
+    @Override
+    public WebSocketServer getSource() {
+        return (WebSocketServer) super.getSource();
+    }
+
+}

+ 24 - 0
hx-socket/src/main/java/com/fjhx/socket/event/WebSocketUserOfflineEvent.java

@@ -0,0 +1,24 @@
+package com.fjhx.socket.event;
+
+import com.fjhx.socket.entity.MessageEntity;
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+import java.util.Date;
+
+/**
+ * webStock推送的用户离线事件
+ */
+@Getter
+public class WebSocketUserOfflineEvent extends ApplicationEvent {
+
+    private final MessageEntity messageEntity = new MessageEntity();
+
+    public WebSocketUserOfflineEvent(Long userId, Object message) {
+        super(userId);
+        this.messageEntity.setUserId(userId);
+        this.messageEntity.setData(message);
+        this.messageEntity.setCreateTime(new Date());
+    }
+
+}

+ 214 - 0
hx-socket/src/main/java/com/fjhx/socket/service/WebSocketServer.java

@@ -0,0 +1,214 @@
+package com.fjhx.socket.service;
+
+import cn.hutool.extra.spring.SpringUtil;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.fjhx.socket.entity.MessageEntity;
+import com.fjhx.socket.event.*;
+import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.framework.web.service.TokenService;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.ApplicationContext;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import javax.websocket.*;
+import javax.websocket.server.PathParam;
+import javax.websocket.server.ServerEndpoint;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@ServerEndpoint("/webStock/{token}")
+@Component
+@Slf4j
+@Getter
+public class WebSocketServer {
+
+    private static final ApplicationContext applicationContext = SpringUtil.getApplicationContext();
+
+    /**
+     * concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
+     */
+    private static final Map<Long, Map<Long, WebSocketServer>> webSocketMap = new ConcurrentHashMap<>();
+    /**
+     * 与某个客户端的连接会话,需要通过它来给客户端发送数据
+     */
+    private Session session;
+    /**
+     * 接收userId
+     */
+    private Long userId;
+    /**
+     * sessionId
+     */
+    private Long sessionId;
+
+    private static final TokenService tokenService = SpringUtil.getBean(TokenService.class);
+
+    /**
+     * 连接建立成功调用的方法
+     */
+    @OnOpen
+    public void onOpen(@RequestBody Session session, @PathParam("token") String token) {
+
+        this.session = session;
+        this.sessionId = IdWorker.getId();
+
+        // 解析token
+        LoginUser loginUser = tokenService.getLoginUser(token);
+
+        if (loginUser == null) {
+            try {
+                this.sendMessage(-1, "token错误");
+                this.session.close();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            return;
+        }
+
+        this.userId = loginUser.getUserId();
+
+        synchronized (this) {
+            Map<Long, WebSocketServer> sessionIdWebSocketServerMap = webSocketMap.computeIfAbsent(userId, k -> new ConcurrentHashMap<>());
+            sessionIdWebSocketServerMap.put(sessionId, this);
+        }
+
+        // 发布建立连接连接事件
+        applicationContext.publishEvent(new WebSocketOnOpenEvent(this));
+    }
+
+    /**
+     * 连接关闭调用的方法
+     */
+    @OnClose
+    public void onClose() {
+        synchronized (this) {
+            if (userId != null) {
+                Map<Long, WebSocketServer> sessionIdWebSocketServerMap = webSocketMap.get(userId);
+                if (sessionIdWebSocketServerMap != null) {
+                    sessionIdWebSocketServerMap.remove(sessionId);
+
+                    if (sessionIdWebSocketServerMap.size() == 0) {
+                        webSocketMap.remove(userId);
+                    }
+
+                }
+            }
+        }
+
+        // 发布建立关闭连接事件
+        applicationContext.publishEvent(new WebSocketOnCloseEvent(this));
+    }
+
+    /**
+     * 收到客户端消息后调用的方法
+     *
+     * @param message 客户端发送过来的消息
+     */
+    @OnMessage
+    public void onMessage(String message) {
+        // 推送消息事件
+        applicationContext.publishEvent(new WebSocketOnMessageEvent(this, message));
+    }
+
+    /**
+     * @param error 异常
+     */
+    @OnError
+    public void onError(Throwable error) {
+        // 发布连接异常事件
+        applicationContext.publishEvent(new WebSocketOnErrorEvent(this, error));
+    }
+
+    /**
+     * 实现服务器主动推送
+     *
+     * @param message 消息内容
+     */
+    public void sendMessage(Integer type, Object message) {
+        MessageEntity sendEntity = new MessageEntity();
+        sendEntity.setUserId(userId);
+        sendEntity.setSessionId(sessionId);
+        sendEntity.setCreateTime(new Date());
+        sendEntity.setType(type);
+        sendEntity.setData(message);
+
+        try {
+            this.session.getBasicRemote().sendText(JSON.toJSONString(sendEntity));
+            applicationContext.publishEvent(new WebSocketSendSuccessEvent(this, sendEntity));
+        } catch (IOException e) {
+            applicationContext.publishEvent(new WebSocketSendFailEvent(this, sendEntity));
+        }
+    }
+
+    /**
+     * 发送自定义消息
+     *
+     * @param userId  发送用户
+     * @param type    消息类型
+     * @param message 消息内容
+     */
+    public static void sendInfo(Long userId, Integer type, Object message) {
+        Map<Long, WebSocketServer> sessionIdWebSocketServerMap = webSocketMap.get(userId);
+
+        if (sessionIdWebSocketServerMap == null) {
+            applicationContext.publishEvent(new WebSocketUserOfflineEvent(userId, message));
+            return;
+        }
+
+        for (WebSocketServer webSocketServer : sessionIdWebSocketServerMap.values()) {
+            webSocketServer.sendMessage(type, message);
+        }
+
+    }
+
+    /**
+     * 发送自定义消息
+     *
+     * @param userId    发送用户
+     * @param sessionId sessionId
+     * @param type      消息类型
+     * @param message   消息内容
+     */
+    public static void sendInfo(Long userId, Long sessionId, Integer type, Object message) {
+        Map<Long, WebSocketServer> sessionIdWebSocketServerMap = webSocketMap.get(userId);
+
+        if (sessionIdWebSocketServerMap == null) {
+            applicationContext.publishEvent(new WebSocketUserOfflineEvent(userId, message));
+            return;
+        }
+
+        WebSocketServer webSocketServer = sessionIdWebSocketServerMap.get(sessionId);
+        if (webSocketServer != null) {
+            webSocketServer.sendMessage(type, message);
+        } else {
+            applicationContext.publishEvent(new WebSocketUserOfflineEvent(userId, message));
+        }
+
+    }
+
+    /**
+     * 发送自定义消息--群发
+     *
+     * @param message 消息内容
+     */
+    public static void sendInfoGroup(Integer type, Object message) {
+        if (webSocketMap.size() > 0) {
+            for (Long userId : WebSocketServer.webSocketMap.keySet()) {
+                sendInfo(userId, type, message);
+            }
+        }
+    }
+
+    /**
+     * 在线人数
+     */
+    public static int getOnlineCount() {
+        return webSocketMap.size();
+    }
+
+}

+ 14 - 0
pom.xml

@@ -174,6 +174,18 @@
                 <version>${ruoyi.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>com.ruoyi</groupId>
+                <artifactId>ruoyi-test</artifactId>
+                <version>${ruoyi.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>com.ruoyi</groupId>
+                <artifactId>hx-socket</artifactId>
+                <version>${ruoyi.version}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>
 
@@ -184,6 +196,8 @@
         <module>ruoyi-quartz</module>
         <module>ruoyi-generator</module>
         <module>ruoyi-common</module>
+        <module>ruoyi-test</module>
+        <module>hx-socket</module>
     </modules>
     <packaging>pom</packaging>
 

+ 10 - 0
ruoyi-admin/pom.xml

@@ -61,6 +61,16 @@
             <artifactId>ruoyi-generator</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>com.ruoyi</groupId>
+            <artifactId>ruoyi-test</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.ruoyi</groupId>
+            <artifactId>hx-socket</artifactId>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 3 - 1
ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java

@@ -3,13 +3,15 @@ package com.ruoyi;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.context.annotation.ComponentScan;
 
 /**
  * 启动程序
  * 
  * @author ruoyi
  */
-@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
+@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class },scanBasePackages = {"com.fjhx.**","com.ruoyi.**"})
+
 public class RuoYiApplication
 {
     public static void main(String[] args)

+ 1 - 1
ruoyi-admin/src/main/resources/application.yml

@@ -75,7 +75,7 @@ token:
   # 令牌密钥
   secret: abcdefghijklmnopqrstuvwxyz
   # 令牌有效期(默认30分钟)
-  expireTime: 30
+  expireTime: 1440
 
 # MyBatis配置
 #mybatis:

+ 6 - 0
ruoyi-common/pom.xml

@@ -146,6 +146,12 @@
             <artifactId>lombok</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.83_noneautotype</version>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 19 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseIdPo.java

@@ -0,0 +1,19 @@
+package com.ruoyi.common.core.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+@Getter
+@Setter
+public class BaseIdPo implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.ASSIGN_ID)
+    private Long id;
+
+}

+ 38 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BasePo.java

@@ -0,0 +1,38 @@
+package com.ruoyi.common.core.domain;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+@Getter
+@Setter
+public class BasePo extends BaseIdPo {
+
+    /**
+     * 创建人
+     */
+    @TableField(fill = FieldFill.INSERT)
+    private Long createUser;
+
+    /**
+     * 创建时间
+     */
+    @TableField(fill = FieldFill.INSERT)
+    private Date createTime;
+
+    /**
+     * 更新人
+     */
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private Long updateUser;
+
+    /**
+     * 更新时间
+     */
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private Date updateTime;
+
+}

+ 91 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseSelectDto.java

@@ -0,0 +1,91 @@
+package com.ruoyi.common.core.domain;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.exception.ServiceException;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Getter
+@Setter
+public class BaseSelectDto implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 通用id
+     */
+    private Long id;
+
+    /**
+     * 页数
+     */
+    private Integer pageNum;
+
+    /**
+     * 每页条数
+     */
+    private Integer pageSize;
+
+    /**
+     * 关键字查询
+     */
+    private String keyword;
+
+    /**
+     * 通用开始时间
+     */
+    private String beginTime;
+
+    /**
+     * 通用结束时间
+     */
+    private String endTime;
+
+    /**
+     * 返回分页实体
+     */
+    public <T> Page<T> getPage() {
+        return new Page<>(getPageNum(), getPageSize());
+    }
+
+    public Integer getPageNum() {
+        return ObjectUtil.defaultIfNull(pageNum, 1);
+    }
+
+    public Integer getPageSize() {
+        return ObjectUtil.defaultIfNull(pageSize, 10);
+    }
+
+    public Date getBeginTime() {
+        if (ObjectUtil.isEmpty(beginTime)) {
+            return null;
+        }
+
+        try {
+            return DateUtil.beginOfDay(DateUtil.parse(beginTime));
+        } catch (Exception e) {
+            throw new ServiceException("开始时间格式错误");
+        }
+
+    }
+
+    public Date getEndTime() {
+
+        if (ObjectUtil.isEmpty(endTime)) {
+            return null;
+        }
+
+        try {
+            return DateUtil.endOfDay(DateUtil.parse(endTime));
+        } catch (Exception e) {
+            throw new ServiceException("结束时间格式错误");
+        }
+
+    }
+
+}

+ 2 - 1
ruoyi-common/src/main/java/com/ruoyi/common/core/service/BaseService.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 
 import java.util.List;
@@ -15,7 +16,7 @@ import java.util.function.Consumer;
 import java.util.stream.Collectors;
 
 @SuppressWarnings({"unused", "unchecked"})
-public interface BaseService<T> extends IService<T> {
+public interface BaseService<T extends BaseIdPo> extends IService<T> {
 
 
     default IWrapper<T> getWrapper() {

+ 11 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResponseAdvice.java

@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
 
 import java.lang.reflect.AnnotatedElement;
+import java.util.LinkedHashMap;
+import java.util.Objects;
 
 /**
  * 做统一格式返回
@@ -29,6 +31,15 @@ public class ResponseAdvice implements ResponseBodyAdvice<Object> {
 
     @Override
     public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
+        // 404处理
+        if (body instanceof LinkedHashMap) {
+            Object status = ((LinkedHashMap<?, ?>) body).get("status");
+            Object error = ((LinkedHashMap<?, ?>) body).get("error");
+            if (Objects.equals(status, 404) && Objects.equals(error, "Not Found")) {
+                return R.fail(404, "Not Found");
+            }
+        }
+
         // 提供一定的灵活度,如果body已经被包装了,就不进行包装
         if (body instanceof R || body instanceof AjaxResult || body instanceof TableDataInfo) {
             return body;

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -111,7 +111,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/register", "/captchaImage").permitAll()
+                .antMatchers("/login", "/register", "/captchaImage","/webStock/*").permitAll()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

+ 25 - 27
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java

@@ -1,12 +1,5 @@
 package com.ruoyi.framework.web.service;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import javax.servlet.http.HttpServletRequest;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
 import com.ruoyi.common.constant.CacheConstants;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.domain.model.LoginUser;
@@ -20,6 +13,14 @@ import eu.bitwalker.useragentutils.UserAgent;
 import io.jsonwebtoken.Claims;
 import io.jsonwebtoken.Jwts;
 import io.jsonwebtoken.SignatureAlgorithm;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 /**
  * token验证处理
@@ -55,35 +56,32 @@ public class TokenService
      *
      * @return 用户信息
      */
-    public LoginUser getLoginUser(HttpServletRequest request)
-    {
+    public LoginUser getLoginUser(HttpServletRequest request) {
         // 获取请求携带的令牌
         String token = getToken(request);
-        if (StringUtils.isNotEmpty(token))
-        {
-            try
-            {
-                Claims claims = parseToken(token);
-                // 解析对应的权限以及用户信息
-                String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
-                String userKey = getTokenKey(uuid);
-                LoginUser user = redisCache.getCacheObject(userKey);
-                return user;
-            }
-            catch (Exception e)
-            {
-            }
+        if (StringUtils.isNotEmpty(token)) {
+            return getLoginUser(token);
         }
         return null;
     }
 
+    public LoginUser getLoginUser(String token) {
+        try {
+            Claims claims = parseToken(token);
+            // 解析对应的权限以及用户信息
+            String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
+            String userKey = getTokenKey(uuid);
+            return redisCache.getCacheObject(userKey);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
     /**
      * 设置用户身份信息
      */
-    public void setLoginUser(LoginUser loginUser)
-    {
-        if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken()))
-        {
+    public void setLoginUser(LoginUser loginUser) {
+        if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) {
             refreshToken(loginUser);
         }
     }

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java

@@ -1,6 +1,6 @@
 package com.ruoyi.system.service;
 
-import com.ruoyi.common.core.service.BaseService;
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.system.domain.SysConfig;
 
 import java.util.List;
@@ -10,7 +10,7 @@ import java.util.List;
  *
  * @author ruoyi
  */
-public interface ISysConfigService extends BaseService<SysConfig> {
+public interface ISysConfigService extends IService<SysConfig> {
     /**
      * 查询参数配置信息
      *

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java

@@ -1,8 +1,8 @@
 package com.ruoyi.system.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.TreeSelect;
 import com.ruoyi.common.core.domain.entity.SysDept;
-import com.ruoyi.common.core.service.BaseService;
 
 import java.util.List;
 
@@ -11,7 +11,7 @@ import java.util.List;
  *
  * @author ruoyi
  */
-public interface ISysDeptService extends BaseService<SysDept> {
+public interface ISysDeptService extends IService<SysDept> {
     /**
      * 查询部门管理数据
      *

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java

@@ -1,7 +1,7 @@
 package com.ruoyi.system.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.entity.SysDictData;
-import com.ruoyi.common.core.service.BaseService;
 
 import java.util.List;
 
@@ -10,7 +10,7 @@ import java.util.List;
  *
  * @author ruoyi
  */
-public interface ISysDictDataService extends BaseService<SysDictData> {
+public interface ISysDictDataService extends IService<SysDictData> {
     /**
      * 根据条件分页查询字典数据
      *

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java

@@ -1,8 +1,8 @@
 package com.ruoyi.system.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.entity.SysDictData;
 import com.ruoyi.common.core.domain.entity.SysDictType;
-import com.ruoyi.common.core.service.BaseService;
 
 import java.util.List;
 
@@ -11,7 +11,7 @@ import java.util.List;
  *
  * @author ruoyi
  */
-public interface ISysDictTypeService extends BaseService<SysDictType> {
+public interface ISysDictTypeService extends IService<SysDictType> {
     /**
      * 根据条件分页查询字典类型
      *

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysLogininforService.java

@@ -1,6 +1,6 @@
 package com.ruoyi.system.service;
 
-import com.ruoyi.common.core.service.BaseService;
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.system.domain.SysLogininfor;
 
 import java.util.List;
@@ -10,7 +10,7 @@ import java.util.List;
  *
  * @author ruoyi
  */
-public interface ISysLogininforService extends BaseService<SysLogininfor> {
+public interface ISysLogininforService extends IService<SysLogininfor> {
     /**
      * 新增系统登录日志
      *

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java

@@ -1,8 +1,8 @@
 package com.ruoyi.system.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.TreeSelect;
 import com.ruoyi.common.core.domain.entity.SysMenu;
-import com.ruoyi.common.core.service.BaseService;
 import com.ruoyi.system.domain.vo.RouterVo;
 
 import java.util.List;
@@ -13,7 +13,7 @@ import java.util.Set;
  *
  * @author ruoyi
  */
-public interface ISysMenuService extends BaseService<SysMenu> {
+public interface ISysMenuService extends IService<SysMenu> {
     /**
      * 根据用户查询系统菜单列表
      *

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java

@@ -1,6 +1,6 @@
 package com.ruoyi.system.service;
 
-import com.ruoyi.common.core.service.BaseService;
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.system.domain.SysNotice;
 
 import java.util.List;
@@ -10,7 +10,7 @@ import java.util.List;
  *
  * @author ruoyi
  */
-public interface ISysNoticeService extends BaseService<SysNotice> {
+public interface ISysNoticeService extends IService<SysNotice> {
     /**
      * 查询公告信息
      *

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOperLogService.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.service.BaseService;
 import com.ruoyi.system.domain.SysOperLog;
 
@@ -10,7 +11,7 @@ import java.util.List;
  *
  * @author ruoyi
  */
-public interface ISysOperLogService extends BaseService<SysOperLog> {
+public interface ISysOperLogService extends IService<SysOperLog> {
     /**
      * 新增操作日志
      *

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.service.BaseService;
 import com.ruoyi.system.domain.SysPost;
 
@@ -10,7 +11,7 @@ import java.util.List;
  *
  * @author ruoyi
  */
-public interface ISysPostService extends BaseService<SysPost> {
+public interface ISysPostService extends IService<SysPost> {
     /**
      * 查询岗位信息集合
      *

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.entity.SysRole;
 import com.ruoyi.common.core.service.BaseService;
 import com.ruoyi.system.domain.SysUserRole;
@@ -12,7 +13,7 @@ import java.util.Set;
  *
  * @author ruoyi
  */
-public interface ISysRoleService extends BaseService<SysRole> {
+public interface ISysRoleService extends IService<SysRole> {
     /**
      * 根据条件分页查询角色数据
      *

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java

@@ -1,7 +1,7 @@
 package com.ruoyi.system.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.entity.SysUser;
-import com.ruoyi.common.core.service.BaseService;
 
 import java.util.List;
 
@@ -10,7 +10,7 @@ import java.util.List;
  *
  * @author ruoyi
  */
-public interface ISysUserService extends BaseService<SysUser> {
+public interface ISysUserService extends IService<SysUser> {
     /**
      * 根据条件分页查询用户列表
      *