pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrIntakeMapper.java
@@ -96,6 +96,13 @@ /** * 根据村Id获取全部地址 * @param intakeId 村Id * @return intakeName 取水口编号 */ String getNameById(@Param("intakeId") Long intakeId); /** * 根据村Id获取全部地址 * @param villageId 村Id * @return address 全部五级地址 */ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/Web2RtuMw.java
@@ -173,7 +173,7 @@ new HttpEntity<>(new HttpHeaders()), BaseResponse.class); } catch (Exception e) { e.printStackTrace(); //e.printStackTrace(); return BaseResponseUtils.buildError("后端系统出错,中间件调用异常"); } if(response == null){ pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
@@ -405,6 +405,13 @@ </select> <!--根据村ID获取全部地址--> <select id="getNameById" resultType="java.lang.String"> select name from pr_intake where id = #{intakeId, jdbcType=BIGINT} </select> <!--根据村ID获取全部地址--> <select id="getAddressByVillageId" parameterType="_long" resultType="java.lang.String"> select CONCAT(dis_province.`name`, dis_city.`name`, dis_county.`name`, dis_town.`name`, dis_village.`name`) AS address pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/PipIrrMwRtuApplication.java
@@ -8,9 +8,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.FilterType; import org.springframework.scheduling.annotation.EnableScheduling; @EnableScheduling @SpringBootApplication @EnableAspectJAutoProxy @ComponentScan(basePackages = {"com.dy.common", "com.dy.pipIrrGlobal", "com.dy.rtuMw"}, pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/msCenter/TestMsResource.java
@@ -1,5 +1,6 @@ package com.dy.rtuMw.server.msCenter; import com.dy.common.util.DateTime; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -9,16 +10,34 @@ * @Description */ //使起作用,本类注解@Component,并在PipIrrMwRtuApplication注解@EnableScheduling @Component //@Component public class TestMsResource { // 设置定时十秒一次 @Scheduled(cron = "0/1 * * * * ?") public void WsHeartBeat() throws Exception { MsObj obj = new MsObj() ; obj.put("id", System.currentTimeMillis()); obj.put("ms", "消息" + System.currentTimeMillis()); MsCenterUnit.getInstance().pushMs(obj); @Scheduled(cron = "0/5 * * * * ?") public void test1() throws Exception { MsObj msObj = new MsObj() ; msObj.put("name", "开阀"); msObj.put("clientId", 1233445345); msObj.put("clientName", "张三"); msObj.put("clientAddress", "北京市"); msObj.put("icCardNo", "123456789"); msObj.put("rtuAddr", "123456789"); msObj.put("intakeId", 987654321); msObj.put("dt", DateTime.yyyy_MM_dd_HH_mm_ss()); MsCenterUnit.getInstance().pushMs(msObj); } // 设置定时十秒一次 @Scheduled(cron = "0/6 * * * * ?") public void test2() throws Exception { MsObj msObj = new MsObj() ; msObj.put("name", "报警"); msObj.put("rtuAddr","123456789"); msObj.put("intakeId", 1233445345); msObj.put("alarm", "水表超量程"); msObj.put("dt", DateTime.yyyy_MM_dd_HH_mm_ss()); MsCenterUnit.getInstance().pushMs(msObj); } } pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/msCenter/CenterMsReceiveCtrl.java
@@ -3,19 +3,20 @@ 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.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.Iterator; import java.util.List; /** @@ -29,6 +30,9 @@ @RestController @RequestMapping(path="msCenter") public class CenterMsReceiveCtrl{ @Autowired private CenterMsReceiveSv sv ; /** * 通信中间消息中心推送消息接收 @@ -45,14 +49,26 @@ if(list != null && list.size() > 0){ for (JSONObject jo : list) { if(jo != null){ log.info("----------------start " + token + " 消息数据--------------") ; Iterator<String> it = jo.keySet().iterator() ; String key ; while (it.hasNext()){ key = it.next() ; log.info(key + ":" + jo.get(key)); 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) ; } } log.info("----------------end " + token + " 消息数据--------------") ; try { WebSocketServer.sendAllMessage(jo.toJSONString()); }catch (Exception e){ log.error("推送消息失败", e) ; } } } } pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/msCenter/CenterMsReceiveSv.java
New file @@ -0,0 +1,25 @@ package com.dy.pipIrrRemote.msCenter; import com.dy.pipIrrGlobal.daoPr.PrIntakeMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** * @Author: liurunyu * @Date: 2025/2/13 14:08 * @Description */ @Slf4j @Service public class CenterMsReceiveSv { @Autowired private PrIntakeMapper intakeDao ; public String selectIntakeName(Long id){ return this.intakeDao.getNameById(id) ; } }