| New file | 
|  |  |  | 
|---|
|  |  |  | package com.dy.pipIrrRemote.msCenter; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSONObject; | 
|---|
|  |  |  | import com.dy.common.contant.Constant; | 
|---|
|  |  |  | import com.dy.common.multiDataSource.DataSourceContext; | 
|---|
|  |  |  | import com.dy.common.util.NumUtil; | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponse; | 
|---|
|  |  |  | import com.dy.common.webUtil.WebSocketMessage; | 
|---|
|  |  |  | import com.dy.pipIrrRemote.largeScreen.WebSocketServer; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Hidden; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.tags.Tag; | 
|---|
|  |  |  | import jakarta.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import jakarta.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.http.MediaType; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.PostMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Author: liurunyu | 
|---|
|  |  |  | * @Date: 2025/2/12 17:34 | 
|---|
|  |  |  | * @Description | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Hidden //不公开接口,其只有通信中间件调用 | 
|---|
|  |  |  | @Tag(name = "通信中间件消息中心推送消息接收者", description = "通信中间件消息中心推送消息接收者") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(path="msCenter") | 
|---|
|  |  |  | public class CenterMsReceiveCtrl{ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CenterMsReceiveSv sv ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 通信中间件消息中心推送消息接收 | 
|---|
|  |  |  | * @param list 消息数据集合 | 
|---|
|  |  |  | * @return 无返回结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Hidden //不公开接口,其只有通信中间件调用 | 
|---|
|  |  |  | @PostMapping(path = "receive", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | public BaseResponse<Boolean> receive(@RequestBody List<JSONObject> list, HttpServletRequest req, HttpServletResponse rep) { | 
|---|
|  |  |  | //通信中间件传过来的机构tag,以用于查找数据源 | 
|---|
|  |  |  | String orgTag = req.getHeader(Constant.TokenKeyInHeader); | 
|---|
|  |  |  | DataSourceContext.set(orgTag); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(list != null && list.size() > 0){ | 
|---|
|  |  |  | for (JSONObject jo : list) { | 
|---|
|  |  |  | if(jo != null){ | 
|---|
|  |  |  | if(jo.containsKey("intakeId")){ | 
|---|
|  |  |  | Object intakeIdObj = jo.get("intakeId") ; | 
|---|
|  |  |  | Long intakeId = null ; | 
|---|
|  |  |  | if(intakeIdObj != null && intakeIdObj instanceof Long){ | 
|---|
|  |  |  | intakeId = (Long) intakeIdObj ; | 
|---|
|  |  |  | }else if(intakeIdObj != null && intakeIdObj instanceof String){ | 
|---|
|  |  |  | if(NumUtil.isPlusIntNumber(intakeIdObj.toString())){ | 
|---|
|  |  |  | intakeId = Long.parseLong(intakeIdObj.toString()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(intakeId != null){ | 
|---|
|  |  |  | String intakeNum = this.sv.selectIntakeName(intakeId) ; | 
|---|
|  |  |  | jo.put("intakeNum", intakeNum) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | sendByWebSocket(orgTag, list) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 通过websocket把消息推送出去,当前接收方是前端的大屏展示模块 | 
|---|
|  |  |  | * @param list | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void sendByWebSocket(String orgTag, List<JSONObject> list){ | 
|---|
|  |  |  | WebSocketMessage vo = new WebSocketMessage() ; | 
|---|
|  |  |  | vo.type = WebSocketMessage.TYPE_JSON ; | 
|---|
|  |  |  | vo.content = list ; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | WebSocketServer.sendMessage2AllClient(orgTag, JSON.toJSONString(vo)); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("推送消息失败", e) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|