20 changed files with 625 additions and 175 deletions
@ -0,0 +1,123 @@ |
|||||
|
/* |
||||
|
* Copyright 2019-2020 Zheng Jie |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.nl.common.websocket; |
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.nl.wms.database.eas.dao.HomeBillCounts; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import javax.websocket.*; |
||||
|
import javax.websocket.server.PathParam; |
||||
|
import javax.websocket.server.ServerEndpoint; |
||||
|
import java.io.IOException; |
||||
|
import java.util.List; |
||||
|
import java.util.concurrent.CopyOnWriteArraySet; |
||||
|
|
||||
|
|
||||
|
@ServerEndpoint("/webSocket/SendHomeInfo/{sid}") |
||||
|
@Slf4j |
||||
|
@Component |
||||
|
public class SendHomeWebSocketServer { |
||||
|
|
||||
|
/** |
||||
|
* concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。 |
||||
|
*/ |
||||
|
private static CopyOnWriteArraySet<SendHomeWebSocketServer> webSocketSet = new CopyOnWriteArraySet<>(); |
||||
|
|
||||
|
/**静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。*/ |
||||
|
private static int onlineCount = 0; |
||||
|
|
||||
|
|
||||
|
/**与某个客户端的连接会话,需要通过它来给客户端发送数据*/ |
||||
|
private Session session; |
||||
|
/** |
||||
|
* 与某个客户端的连接会话,需要通过它来给客户端发送数据 |
||||
|
*/ |
||||
|
/** |
||||
|
* 接收sid |
||||
|
*/ |
||||
|
private String sid = ""; |
||||
|
|
||||
|
/** |
||||
|
* 连接建立成功调用的方法 |
||||
|
*/ |
||||
|
@OnOpen |
||||
|
public void onOpen(Session session, @PathParam("sid") String sid) { |
||||
|
this.session = session; |
||||
|
//如果存在就先删除一个,防止重复推送消息
|
||||
|
webSocketSet.removeIf(webSocket -> webSocket.sid.equals(sid)); |
||||
|
webSocketSet.add(this); |
||||
|
this.sid = sid; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 连接关闭调用的方法 |
||||
|
*/ |
||||
|
@OnClose |
||||
|
public void onClose() { |
||||
|
webSocketSet.remove(this); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 收到客户端消息后调用的方法 |
||||
|
* |
||||
|
* @param message 客户端发送过来的消息 |
||||
|
*/ |
||||
|
@OnMessage |
||||
|
public void onMessage(String message, Session session) { |
||||
|
System.out.println(webSocketSet.size() + "_接收到消息_" + session.getId()); |
||||
|
} |
||||
|
|
||||
|
@OnError |
||||
|
public void onError(Session session, Throwable error) { |
||||
|
//log.error("发生错误");
|
||||
|
webSocketSet.remove(session); |
||||
|
error.printStackTrace(); |
||||
|
} |
||||
|
|
||||
|
public Session getSession() { |
||||
|
Integer d = 1; |
||||
|
return session; |
||||
|
} |
||||
|
// 发送消息,在定时任务中会调用此方法
|
||||
|
public void sendMessage(String message) throws IOException { |
||||
|
this.session.getBasicRemote().sendText(message); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void sendDataToClient(List<HomeBillCounts> data) { |
||||
|
try { |
||||
|
if (this.session != null&& data != null && !data.isEmpty()) { |
||||
|
this.session.getBasicRemote().sendText(JSON.toJSONString(data)); |
||||
|
} |
||||
|
} catch (IOException e) { |
||||
|
log.error("发送消息给客户端失败", e); |
||||
|
} |
||||
|
} |
||||
|
public static synchronized int getOnlineCount() { |
||||
|
return onlineCount; |
||||
|
} |
||||
|
|
||||
|
public static CopyOnWriteArraySet<SendHomeWebSocketServer> getWebSocketSet() { |
||||
|
return webSocketSet; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setSession(Session session) { |
||||
|
this.session = session; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,153 @@ |
|||||
|
server: |
||||
|
port: 8012 |
||||
|
#配置数据源 |
||||
|
spring: |
||||
|
autoconfigure: |
||||
|
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure |
||||
|
datasource: |
||||
|
dynamic: |
||||
|
primary: mysql |
||||
|
datasource: |
||||
|
mysql: |
||||
|
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy |
||||
|
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:nl_sq_wms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true |
||||
|
username: ${DB_USER:generallu} |
||||
|
password: ${DB_PWD:123456} |
||||
|
type: com.alibaba.druid.pool.DruidDataSource |
||||
|
mysql_srm: |
||||
|
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy |
||||
|
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:nl_sq_wms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true |
||||
|
username: ${DB_USER:wms_third} |
||||
|
password: ${DB_PWD:NOBLElift@!#wms} |
||||
|
type: com.alibaba.druid.pool.DruidDataSource |
||||
|
oracle_eas: |
||||
|
driver-class-name: oracle.jdbc.OracleDriver |
||||
|
url: jdbc:oracle:thin:@localhost:1521:orcl |
||||
|
username: ${DB_USER:user1} |
||||
|
password: ${DB_PWD:Noble12319} |
||||
|
type: com.alibaba.druid.pool.DruidDataSource |
||||
|
sqlserver: |
||||
|
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver |
||||
|
url: jdbc:sqlserver://10.93.41.2\WINCC;DatabaseName=马钢_RH |
||||
|
username: ${DB_USER:sa} |
||||
|
password: ${DB_PWD:123} |
||||
|
type: com.alibaba.druid.pool.DruidDataSource |
||||
|
redis: |
||||
|
#数据库索引 |
||||
|
host: ${REDIS_HOST:127.0.0.1} |
||||
|
port: ${REDIS_PORT:6379} |
||||
|
password: ${REDIS_PWD:} |
||||
|
redisson: |
||||
|
config: | |
||||
|
threads: 4 |
||||
|
nettyThreads: 4 |
||||
|
singleServerConfig: |
||||
|
database: 3 |
||||
|
connectionMinimumIdleSize: 8 |
||||
|
connectionPoolSize: 8 |
||||
|
address: redis://127.0.0.1:6379 |
||||
|
idleConnectionTimeout: 10000 |
||||
|
timeout: 3000 |
||||
|
|
||||
|
|
||||
|
# 登录相关配置 |
||||
|
login: |
||||
|
# 登录缓存 |
||||
|
cache-enable: true |
||||
|
# 是否限制单用户登录 |
||||
|
single-login: false |
||||
|
# 验证码 |
||||
|
login-code: |
||||
|
# 验证码类型配置 查看 LoginProperties 类 |
||||
|
code-type: arithmetic |
||||
|
# 登录图形验证码有效时间/分钟 |
||||
|
expiration: 2 |
||||
|
# 验证码高度 |
||||
|
width: 111 |
||||
|
# 验证码宽度 |
||||
|
heigth: 36 |
||||
|
# 内容长度 |
||||
|
length: 2 |
||||
|
# 字体名称,为空则使用默认字体 |
||||
|
font-name: |
||||
|
# 字体大小 |
||||
|
font-size: 25 |
||||
|
|
||||
|
#是否允许生成代码,生产环境设置为false |
||||
|
generator: |
||||
|
enabled: true |
||||
|
|
||||
|
#是否开启 swagger-ui |
||||
|
swagger: |
||||
|
enabled: true |
||||
|
|
||||
|
# IP 本地解析 |
||||
|
ip: |
||||
|
local-parsing: true |
||||
|
|
||||
|
# 文件存储路径 |
||||
|
file: |
||||
|
mac: |
||||
|
path: ~/file/ |
||||
|
avatar: ~/avatar/ |
||||
|
linux: |
||||
|
path: /home/eladmin/file/ |
||||
|
avatar: /home/eladmin/avatar/ |
||||
|
windows: |
||||
|
path: C:\eladmin\file\ |
||||
|
avatar: C:\eladmin\avatar\ |
||||
|
# 文件大小 /M |
||||
|
maxSize: 100 |
||||
|
avatarMaxSize: 5 |
||||
|
logging: |
||||
|
file: |
||||
|
path: C:\log\wms |
||||
|
config: classpath:logback-spring.xml |
||||
|
|
||||
|
# Sa-Token配置 |
||||
|
sa-token: |
||||
|
# token 名称 (同时也是cookie名称) |
||||
|
token-name: Authorization |
||||
|
# token 有效期,单位s 默认30天, -1代表永不过期 |
||||
|
timeout: 2592000 |
||||
|
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒 |
||||
|
activity-timeout: -1 |
||||
|
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) |
||||
|
is-concurrent: true |
||||
|
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token) |
||||
|
is-share: false |
||||
|
# token风格 |
||||
|
token-style: random-128 |
||||
|
# 是否输出操作日志 |
||||
|
is-log: false |
||||
|
jwt-secret-key: opsjajisdnnca0sdkksdfaaasdfwwq |
||||
|
# token 前缀 |
||||
|
token-prefix: Bearer |
||||
|
sso: |
||||
|
# Ticket有效期 (单位: 秒),默认五分钟 |
||||
|
ticket-timeout: 300 |
||||
|
# 所有允许的授权回调地址 |
||||
|
allow-url: "*" |
||||
|
# 是否打开单点注销功能 |
||||
|
is-slo: true |
||||
|
# ------- SSO-模式三相关配置 (下面的配置在SSO模式三并且 is-slo=true 时打开) |
||||
|
# 是否打开模式三 |
||||
|
isHttp: true |
||||
|
# 接口调用秘钥(用于SSO模式三的单点注销功能) |
||||
|
secretkey: kQwIOrYvnXmSDkwEiFngrKidMcdrgKor |
||||
|
# ---- 除了以上配置项,你还需要为 Sa-Token 配置http请求处理器(文档有步骤说明) |
||||
|
is-read-cookie: true |
||||
|
is-print: false |
||||
|
# 未登录 StpUtil.getTokenSession() 设置值,获取值 @SaIgnore 得忽略接口 |
||||
|
token-session-check-login: false |
||||
|
alone-redis: |
||||
|
# Redis数据库索引(默认为0) |
||||
|
database: 1 |
||||
|
# Redis服务器地址 |
||||
|
host: 127.0.0.1 |
||||
|
# Redis服务器连接端口 |
||||
|
port: 6379 |
||||
|
# Redis服务器连接密码(默认为空) |
||||
|
password: |
||||
|
# 连接超时时间 |
||||
|
timeout: 10s |
Loading…
Reference in new issue