Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pension
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mengmeng
pension
Commits
06b844fa
Commit
06b844fa
authored
May 17, 2021
by
Shen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 添加WebSocket对订单进行PC端的通知
2. Shiro开放WebSocket 3. 添加NewRestTemplate类对第三方接口的请求 4. 需要对websocket用户身份进行分别通知
parent
38e96398
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
143 additions
and
0 deletions
+143
-0
WebSocketConfig.java
.../src/main/java/io/hmit/common/config/WebSocketConfig.java
+20
-0
WebSocket.java
hmit-admin/src/main/java/io/hmit/common/utils/WebSocket.java
+58
-0
ShiroConfig.java
...ain/java/io/hmit/modules/security/config/ShiroConfig.java
+1
-0
WebSocketController.java
...a/io/hmit/modules/sys/controller/WebSocketController.java
+34
-0
PensionOrderController.java
...dules/serviceOrder/controller/PensionOrderController.java
+1
-0
PensionOrderServiceImpl.java
...es/serviceOrder/service/impl/PensionOrderServiceImpl.java
+2
-0
NewRestTemplate.java
...n/src/main/java/io/hmit/common/utils/NewRestTemplate.java
+23
-0
pom.xml
pom.xml
+4
-0
No files found.
hmit-admin/src/main/java/io/hmit/common/config/WebSocketConfig.java
0 → 100644
View file @
06b844fa
package
io
.
hmit
.
common
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.socket.server.standard.ServerEndpointExporter
;
/**
* @Description : WebSocket配置
* @Author : Shen Yuanfeng
* @Date : 2021/5/17 16:29
*/
@Component
public
class
WebSocketConfig
{
@Bean
public
ServerEndpointExporter
serverEndpointExporter
()
{
return
new
ServerEndpointExporter
();
}
}
hmit-admin/src/main/java/io/hmit/common/utils/WebSocket.java
0 → 100644
View file @
06b844fa
package
io
.
hmit
.
common
.
utils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
javax.websocket.OnClose
;
import
javax.websocket.OnMessage
;
import
javax.websocket.OnOpen
;
import
javax.websocket.Session
;
import
javax.websocket.server.ServerEndpoint
;
import
java.util.concurrent.CopyOnWriteArraySet
;
/**
* @Description : websocket
* @Author : Shen Yuanfeng
* @Date : 2021/5/17 16:31
*/
@Slf4j
@Component
@ServerEndpoint
(
"/webSocket"
)
public
class
WebSocket
{
private
Session
session
;
private
static
CopyOnWriteArraySet
<
WebSocket
>
webSocketSet
=
new
CopyOnWriteArraySet
<>();
@OnOpen
public
void
opOpen
(
Session
session
)
{
this
.
session
=
session
;
webSocketSet
.
add
(
this
);
log
.
info
(
"【WebSocket】有一个新的连接,总数:{}"
,
webSocketSet
.
size
());
}
@OnClose
public
void
onClose
()
{
webSocketSet
.
remove
(
this
);
log
.
info
(
"【WebSocket】连接断开,总数:{}"
,
webSocketSet
.
size
());
}
@OnMessage
public
void
onMessage
(
String
message
)
{
log
.
info
(
"【WebSocket】收到客户端发来的消息:{}"
,
message
);
}
public
void
sendMessage
(
String
message
)
{
for
(
WebSocket
webSocket
:
webSocketSet
)
{
log
.
info
(
"【WebSocket】广播消息,message={}"
,
message
);
try
{
webSocket
.
session
.
getBasicRemote
().
sendText
(
message
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
hmit-admin/src/main/java/io/hmit/modules/security/config/ShiroConfig.java
View file @
06b844fa
...
@@ -58,6 +58,7 @@ public class ShiroConfig {
...
@@ -58,6 +58,7 @@ public class ShiroConfig {
Map
<
String
,
String
>
filterMap
=
new
LinkedHashMap
<>();
Map
<
String
,
String
>
filterMap
=
new
LinkedHashMap
<>();
filterMap
.
put
(
"/static/**"
,
"anon"
);
filterMap
.
put
(
"/static/**"
,
"anon"
);
filterMap
.
put
(
"/webSocket/**"
,
"anon"
);
filterMap
.
put
(
"/webjars/**"
,
"anon"
);
filterMap
.
put
(
"/webjars/**"
,
"anon"
);
filterMap
.
put
(
"/druid/**"
,
"anon"
);
filterMap
.
put
(
"/druid/**"
,
"anon"
);
filterMap
.
put
(
"/login"
,
"anon"
);
filterMap
.
put
(
"/login"
,
"anon"
);
...
...
hmit-admin/src/main/java/io/hmit/modules/sys/controller/WebSocketController.java
0 → 100644
View file @
06b844fa
package
io
.
hmit
.
modules
.
sys
.
controller
;
import
io.hmit.common.utils.WebSocket
;
import
io.hmit.modules.serviceOrder.dto.PensionOrderDTO
;
import
io.hmit.modules.serviceOrder.service.PensionOrderService
;
import
org.springframework.beans.factory.annotation.Autowired
;
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
;
/**
* @Description : 通过websocket通知
* @Author : Shen Yuanfeng
* @Date : 2021/5/17 17:05
*/
@RestController
@RequestMapping
(
"/webSocket"
)
public
class
WebSocketController
{
@Autowired
private
WebSocket
webSocket
;
@Autowired
private
PensionOrderService
pensionOrderService
;
@GetMapping
(
"notify"
)
public
String
doNotify
(
@RequestParam
(
"orderId"
)
Long
orderId
)
{
PensionOrderDTO
pensionOrderDTO
=
pensionOrderService
.
get
(
orderId
);
webSocket
.
sendMessage
(
"新订单-服务id:"
+
pensionOrderDTO
.
getServiceId
());
return
"success"
;
}
}
hmit-api/src/main/java/io/hmit/modules/serviceOrder/controller/PensionOrderController.java
View file @
06b844fa
...
@@ -5,6 +5,7 @@ import io.hmit.annotation.Login;
...
@@ -5,6 +5,7 @@ import io.hmit.annotation.Login;
import
io.hmit.annotation.LoginUser
;
import
io.hmit.annotation.LoginUser
;
import
io.hmit.common.constant.Constant
;
import
io.hmit.common.constant.Constant
;
import
io.hmit.common.page.PageData
;
import
io.hmit.common.page.PageData
;
import
io.hmit.common.utils.NewRestTemplate
;
import
io.hmit.common.utils.Result
;
import
io.hmit.common.utils.Result
;
import
io.hmit.common.validator.AssertUtils
;
import
io.hmit.common.validator.AssertUtils
;
import
io.hmit.common.validator.ValidatorUtils
;
import
io.hmit.common.validator.ValidatorUtils
;
...
...
hmit-api/src/main/java/io/hmit/modules/serviceOrder/service/impl/PensionOrderServiceImpl.java
View file @
06b844fa
...
@@ -6,6 +6,7 @@ import io.hmit.common.constant.Constant;
...
@@ -6,6 +6,7 @@ import io.hmit.common.constant.Constant;
import
io.hmit.common.page.PageData
;
import
io.hmit.common.page.PageData
;
import
io.hmit.common.service.impl.CrudServiceImpl
;
import
io.hmit.common.service.impl.CrudServiceImpl
;
import
io.hmit.common.utils.ConvertUtils
;
import
io.hmit.common.utils.ConvertUtils
;
import
io.hmit.common.utils.NewRestTemplate
;
import
io.hmit.entity.UserEntity
;
import
io.hmit.entity.UserEntity
;
import
io.hmit.modules.serviceOrder.dao.PensionOrderDao
;
import
io.hmit.modules.serviceOrder.dao.PensionOrderDao
;
import
io.hmit.modules.serviceOrder.dto.*
;
import
io.hmit.modules.serviceOrder.dto.*
;
...
@@ -92,6 +93,7 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
...
@@ -92,6 +93,7 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
PensionOrderServiceDTO
orderServiceDTO
=
new
PensionOrderServiceDTO
().
assemblePensionOrderService
(
pensionOrderDTO
);
PensionOrderServiceDTO
orderServiceDTO
=
new
PensionOrderServiceDTO
().
assemblePensionOrderService
(
pensionOrderDTO
);
pensionOrderServiceService
.
save
(
orderServiceDTO
);
pensionOrderServiceService
.
save
(
orderServiceDTO
);
pushMessage
.
sendWeChatMsg
(
pensionOrderDTO
,
userService
.
getUserByUserId
(
pensionOrderDTO
.
getCreator
()).
getOpenid
(),
"oldman"
);
pushMessage
.
sendWeChatMsg
(
pensionOrderDTO
,
userService
.
getUserByUserId
(
pensionOrderDTO
.
getCreator
()).
getOpenid
(),
"oldman"
);
NewRestTemplate
.
getNewOrder
(
pensionOrderDTO
.
getId
().
toString
());
// pushMessage.sendSMSMsg(pensionOrderDTO, userService.getUserByUserId(pensionOrderDTO.getCreator()).getOpenid());
// pushMessage.sendSMSMsg(pensionOrderDTO, userService.getUserByUserId(pensionOrderDTO.getCreator()).getOpenid());
}
}
...
...
hmit-common/src/main/java/io/hmit/common/utils/NewRestTemplate.java
0 → 100644
View file @
06b844fa
package
io
.
hmit
.
common
.
utils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.client.RestTemplate
;
import
java.net.URI
;
/**
* @Description : 内部请求第三方接口
* @Author : Shen Yuanfeng
* @Date : 2021/5/17 17:15
*/
@Slf4j
public
class
NewRestTemplate
{
public
static
void
getNewOrder
(
String
orderId
){
RestTemplate
restTemplate
=
new
RestTemplate
();
String
url
=
"http://127.0.0.1:8088/hmit-admin/webSocket/notify?orderId="
+
orderId
;
String
trans
=
restTemplate
.
getForObject
(
url
,
String
.
class
);
log
.
info
(
"trans = {}"
,
trans
);
}
}
pom.xml
View file @
06b844fa
...
@@ -195,6 +195,10 @@
...
@@ -195,6 +195,10 @@
<artifactId>
lombok
</artifactId>
<artifactId>
lombok
</artifactId>
<version>
${lombok.version}
</version>
<version>
${lombok.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-websocket
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
com.github.binarywang
</groupId>
<groupId>
com.github.binarywang
</groupId>
<artifactId>
weixin-java-mp
</artifactId>
<artifactId>
weixin-java-mp
</artifactId>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment