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
c3f9539c
Commit
c3f9539c
authored
May 18, 2021
by
Shen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 对新订单进行WebSocket对应机构的通知
parent
06b844fa
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
6 deletions
+45
-6
WebSocket.java
hmit-admin/src/main/java/io/hmit/common/utils/WebSocket.java
+24
-3
PensionOrganizationServiceDao.java
...dules/serviceOrder/dao/PensionOrganizationServiceDao.java
+2
-0
PensionOrganizationService.java
...ules/serviceOrder/service/PensionOrganizationService.java
+2
-0
PensionOrderServiceImpl.java
...es/serviceOrder/service/impl/PensionOrderServiceImpl.java
+0
-1
PensionOrganizationServiceImpl.java
...iceOrder/service/impl/PensionOrganizationServiceImpl.java
+5
-0
WebSocketController.java
...a/io/hmit/modules/sys/controller/WebSocketController.java
+7
-2
PensionOrganizationServiceDao.xml
...ces/mapper/serviceOrder/PensionOrganizationServiceDao.xml
+5
-0
No files found.
hmit-admin/src/main/java/io/hmit/common/utils/WebSocket.java
View file @
c3f9539c
...
...
@@ -7,7 +7,10 @@ import javax.websocket.OnClose;
import
javax.websocket.OnMessage
;
import
javax.websocket.OnOpen
;
import
javax.websocket.Session
;
import
javax.websocket.server.PathParam
;
import
javax.websocket.server.ServerEndpoint
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.CopyOnWriteArraySet
;
/**
...
...
@@ -18,16 +21,23 @@ import java.util.concurrent.CopyOnWriteArraySet;
@Slf4j
@Component
@ServerEndpoint
(
"/webSocket"
)
@ServerEndpoint
(
"/webSocket
/{orgId}
"
)
public
class
WebSocket
{
private
Session
session
;
private
static
CopyOnWriteArraySet
<
WebSocket
>
webSocketSet
=
new
CopyOnWriteArraySet
<>();
private
static
Map
<
String
,
WebSocket
>
clients
=
new
ConcurrentHashMap
<
String
,
WebSocket
>();
private
String
orgId
;
@OnOpen
public
void
opOpen
(
Session
session
)
{
public
void
opOpen
(
@PathParam
(
"orgId"
)
String
orgId
,
Session
session
)
{
this
.
session
=
session
;
this
.
orgId
=
orgId
;
log
.
info
(
"【WebSocket】机构上线:{}"
,
orgId
);
clients
.
put
(
orgId
,
this
);
webSocketSet
.
add
(
this
);
log
.
info
(
"【WebSocket】有一个新的连接,总数:{}"
,
webSocketSet
.
size
());
}
...
...
@@ -35,6 +45,7 @@ public class WebSocket {
@OnClose
public
void
onClose
()
{
webSocketSet
.
remove
(
this
);
clients
.
remove
(
orgId
);
log
.
info
(
"【WebSocket】连接断开,总数:{}"
,
webSocketSet
.
size
());
}
...
...
@@ -44,13 +55,23 @@ public class WebSocket {
log
.
info
(
"【WebSocket】收到客户端发来的消息:{}"
,
message
);
}
public
void
sendMessageToOrg
(
String
message
,
String
orgId
)
{
message
=
"您有新的订单:"
+
message
;
for
(
WebSocket
webSocket
:
clients
.
values
())
{
if
(
webSocket
.
orgId
.
equals
(
orgId
)
)
{
webSocket
.
session
.
getAsyncRemote
().
sendText
(
message
);
break
;
}
}
}
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
();
//
e.printStackTrace();
}
}
}
...
...
hmit-admin/src/main/java/io/hmit/modules/serviceOrder/dao/PensionOrganizationServiceDao.java
View file @
c3f9539c
...
...
@@ -23,4 +23,6 @@ public interface PensionOrganizationServiceDao extends BaseDao<PensionOrganizati
Long
getUserOrgId
(
Long
userId
);
Long
findOrgIdByServiceId
(
Long
orgId
);
}
hmit-admin/src/main/java/io/hmit/modules/serviceOrder/service/PensionOrganizationService.java
View file @
c3f9539c
...
...
@@ -22,4 +22,6 @@ public interface PensionOrganizationService extends CrudService<PensionOrganizat
PensionOrganizationDTO
getUserOrg
(
Long
userId
);
Long
findOrgIdByServiceId
(
Long
orderId
);
}
hmit-admin/src/main/java/io/hmit/modules/serviceOrder/service/impl/PensionOrderServiceImpl.java
View file @
c3f9539c
...
...
@@ -59,7 +59,6 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
return
wrapper
;
}
@Override
public
PageData
<
PensionOrderDTO
>
getOrganizationOrder
(
Map
<
String
,
Object
>
params
,
Long
userId
)
{
//登录->查询登录人员所属机构ID->机构ID查询服务ID(List)->服务ID + 状态查询订单(List)
...
...
hmit-admin/src/main/java/io/hmit/modules/serviceOrder/service/impl/PensionOrganizationServiceImpl.java
View file @
c3f9539c
...
...
@@ -60,4 +60,9 @@ public class PensionOrganizationServiceImpl extends CrudServiceImpl<PensionOrgan
public
PensionOrganizationDTO
getUserOrg
(
Long
userId
)
{
return
ConvertUtils
.
sourceToTarget
(
pensionOrganizationDao
.
getOrgByUserId
(
userId
),
PensionOrganizationDTO
.
class
);
}
@Override
public
Long
findOrgIdByServiceId
(
Long
orderId
)
{
return
pensionOrganizationServiceDao
.
findOrgIdByServiceId
(
orderId
);
}
}
hmit-admin/src/main/java/io/hmit/modules/sys/controller/WebSocketController.java
View file @
c3f9539c
...
...
@@ -3,6 +3,7 @@ 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
io.hmit.modules.serviceOrder.service.PensionOrganizationService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -25,10 +26,14 @@ public class WebSocketController {
@Autowired
private
PensionOrderService
pensionOrderService
;
@Autowired
private
PensionOrganizationService
pensionOrganizationService
;
@GetMapping
(
"notify"
)
public
String
doNotify
(
@RequestParam
(
"orderId"
)
Long
orderId
)
{
PensionOrderDTO
pensionOrderDTO
=
pensionOrderService
.
get
(
orderId
);
webSocket
.
sendMessage
(
"新订单-服务id:"
+
pensionOrderDTO
.
getServiceId
());
// PensionOrderDTO pensionOrderDTO = pensionOrderService.get(orderId);
Long
orgId
=
pensionOrganizationService
.
findOrgIdByServiceId
(
orderId
);
webSocket
.
sendMessageToOrg
(
orderId
.
toString
(),
orgId
.
toString
());
return
"success"
;
}
}
hmit-admin/src/main/resources/mapper/serviceOrder/PensionOrganizationServiceDao.xml
View file @
c3f9539c
...
...
@@ -21,4 +21,9 @@
FROM pension_organization_user WHERE user_id = #{userId}
</select>
<select
id=
"findOrgIdByServiceId"
resultType=
"Long"
>
SELECT pos.organization_id FROM pension_order po, pension_organization_service pos
WHERE po.service_id = pos.service_id AND po.id = #{orderId}
</select>
</mapper>
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