pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrControllerMapper.java
@@ -86,4 +86,11 @@ * @return */ Integer deleteIntakeId(@Param("controllerId") Long controllerId); /** * 根据取水口ID获取阀控器地址 * @param intakeId 取水口ID * @return 阀控器地址 */ String getRtuAddrByIntakeId(Long intakeId); } pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoRm/RmCommandHistoryMapper.java
New file @@ -0,0 +1,27 @@ package com.dy.pipIrrGlobal.daoRm; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory; import org.apache.ibatis.annotations.Mapper; /** * @author ZhuBaoMin * @date 2024-05-22 14:29 * @LastEditTime 2024-05-22 14:29 * @Description */ @Mapper public interface RmCommandHistoryMapper extends BaseMapper<RmCommandHistory> { int deleteByPrimaryKey(Long id); int insert(RmCommandHistory record); int insertSelective(RmCommandHistory record); RmCommandHistory selectByPrimaryKey(Long id); int updateByPrimaryKeySelective(RmCommandHistory record); int updateByPrimaryKey(RmCommandHistory record); } pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoRm/RmCommandHistory.java
New file @@ -0,0 +1,116 @@ package com.dy.pipIrrGlobal.pojoRm; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.annotation.JSONField; import com.alibaba.fastjson2.writer.ObjectWriterImplToString; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import com.dy.common.po.BaseEntity; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.*; import java.util.Date; /** * @author ZhuBaoMin * @date 2024-05-21 16:53 * @LastEditTime 2024-05-21 16:53 * @Description 命令日志实体类 */ /** * 命令日志表 */ @TableName(value = "rm_command_history", autoResultMap = true) @Data @Builder @ToString @NoArgsConstructor @AllArgsConstructor public class RmCommandHistory implements BaseEntity{ public static final long serialVersionUID = 202401151517005L; /** * 主键 */ @JSONField(serializeUsing = ObjectWriterImplToString.class) @TableId(type = IdType.INPUT) private Long id; /** * 功能码 */ @JSONField(serializeUsing = ObjectWriterImplToString.class) @NotBlank(message = "功能码不能为空") private String commandCode; /** * 操作内容 */ private String commandName; /** * 阀控器地址 */ @NotBlank(message = "阀控器地址不能为空") private String rtuaddr; /** * 通讯协议 */ @NotBlank(message = "通讯协议不能为空") private String protocol; /** * 命令类型 */ @NotBlank(message = "命令类型不能为空") private String commandType; /** * 回调URL */ @NotBlank(message = "回调URL不能为空") private String callback; /** * 参数数据 */ @TableField(typeHandler = JacksonTypeHandler.class) private JSONObject param; /** * 发送命令时间 */ @NotNull(message = "发送命令时间不能为空") private Date sendTime; /** * 操作人 */ @JSONField(serializeUsing = ObjectWriterImplToString.class) @NotNull(message = "操作人不能为空") private Long operator; /** * 命令结果;0-失败,1-成功 */ private Byte result; /** * 收到命令结果时间 */ private Date resultTime; /** * 命令结果内容 */ @TableField(typeHandler = JacksonTypeHandler.class) private JSONObject resultText; } pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrControllerMapper.xml
@@ -251,4 +251,9 @@ <select id="getBindedCount" resultType="java.lang.Integer"> SELECT COUNT(*) AS recordCount FROM pr_controller WHERE rtuAddr = (SELECT rtuAddr FROM pr_controller_tramp WHERE id = ${controllerId}) AND intakeId IS NOT NULL </select> <!--根据取水口ID获取阀控器地址--> <select id="getRtuAddrByIntakeId" resultType="java.lang.String"> SELECT rtuAddr FROM pr_controller WHERE deleted = 0 AND intakeId = #{intakeId} LIMIT 0,1 </select> </mapper> pipIrr-platform/pipIrr-global/src/main/resources/mapper/RmCommandHistoryMapper.xml
New file @@ -0,0 +1,199 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper"> <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoRm.RmCommandHistory"> <!--@mbg.generated--> <!--@Table rm_command_history--> <id column="id" jdbcType="BIGINT" property="id" /> <result column="command_code" jdbcType="VARCHAR" property="commandCode" /> <result column="command_name" jdbcType="VARCHAR" property="commandName" /> <result column="rtuAddr" jdbcType="VARCHAR" property="rtuaddr" /> <result column="protocol" jdbcType="VARCHAR" property="protocol" /> <result column="command_type" jdbcType="VARCHAR" property="commandType" /> <result column="callBack" jdbcType="VARCHAR" property="callback" /> <!-- <result column="param" jdbcType="VARCHAR" property="param" />--> <result column="param" property="param" jdbcType="JAVA_OBJECT" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" /> <result column="send_time" jdbcType="TIMESTAMP" property="sendTime" /> <result column="operator" jdbcType="BIGINT" property="operator" /> <result column="result" jdbcType="TINYINT" property="result" /> <result column="result_time" jdbcType="TIMESTAMP" property="resultTime" /> <result column="result_text" property="resultText" jdbcType="JAVA_OBJECT" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" /> </resultMap> <sql id="Base_Column_List"> <!--@mbg.generated--> id, command_code, command_name, rtuAddr, protocol, command_type, callBack, param, send_time, `operator`, `result`, result_time, result_text </sql> <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> <!--@mbg.generated--> select <include refid="Base_Column_List" /> from rm_command_history where id = #{id,jdbcType=BIGINT} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> <!--@mbg.generated--> delete from rm_command_history where id = #{id,jdbcType=BIGINT} </delete> <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoRm.RmCommandHistory"> <!--@mbg.generated--> insert into rm_command_history (id, command_code, command_name, rtuAddr, protocol, command_type, callBack, param, send_time, `operator`, `result`, result_time, result_text) values (#{id,jdbcType=BIGINT}, #{commandCode,jdbcType=VARCHAR}, #{commandName,jdbcType=VARCHAR}, #{rtuaddr,jdbcType=VARCHAR}, #{protocol,jdbcType=VARCHAR}, #{commandType,jdbcType=VARCHAR}, #{callback,jdbcType=VARCHAR}, #{param,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, #{sendTime,jdbcType=TIMESTAMP}, #{operator,jdbcType=BIGINT}, #{result,jdbcType=TINYINT}, #{resultTime,jdbcType=TIMESTAMP}, #{resultText,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}) </insert> <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoRm.RmCommandHistory"> <!--@mbg.generated--> insert into rm_command_history <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> id, </if> <if test="commandCode != null"> command_code, </if> <if test="commandName != null"> command_name, </if> <if test="rtuaddr != null"> rtuAddr, </if> <if test="protocol != null"> protocol, </if> <if test="commandType != null"> command_type, </if> <if test="callback != null"> callBack, </if> <if test="param != null"> param, </if> <if test="sendTime != null"> send_time, </if> <if test="operator != null"> `operator`, </if> <if test="result != null"> `result`, </if> <if test="resultTime != null"> result_time, </if> <if test="resultText != null"> result_text, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> #{id,jdbcType=BIGINT}, </if> <if test="commandCode != null"> #{commandCode,jdbcType=VARCHAR}, </if> <if test="commandName != null"> #{commandName,jdbcType=VARCHAR}, </if> <if test="rtuaddr != null"> #{rtuaddr,jdbcType=VARCHAR}, </if> <if test="protocol != null"> #{protocol,jdbcType=VARCHAR}, </if> <if test="commandType != null"> #{commandType,jdbcType=VARCHAR}, </if> <if test="callback != null"> #{callback,jdbcType=VARCHAR}, </if> <if test="param != null"> #{param,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, </if> <if test="sendTime != null"> #{sendTime,jdbcType=TIMESTAMP}, </if> <if test="operator != null"> #{operator,jdbcType=BIGINT}, </if> <if test="result != null"> #{result,jdbcType=TINYINT}, </if> <if test="resultTime != null"> #{resultTime,jdbcType=TIMESTAMP}, </if> <if test="resultText != null"> #{resultText,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoRm.RmCommandHistory"> <!--@mbg.generated--> update rm_command_history <set> <if test="commandCode != null"> command_code = #{commandCode,jdbcType=VARCHAR}, </if> <if test="commandName != null"> command_name = #{commandName,jdbcType=VARCHAR}, </if> <if test="rtuaddr != null"> rtuAddr = #{rtuaddr,jdbcType=VARCHAR}, </if> <if test="protocol != null"> protocol = #{protocol,jdbcType=VARCHAR}, </if> <if test="commandType != null"> command_type = #{commandType,jdbcType=VARCHAR}, </if> <if test="callback != null"> callBack = #{callback,jdbcType=VARCHAR}, </if> <if test="param != null"> param = #{param,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, </if> <if test="sendTime != null"> send_time = #{sendTime,jdbcType=TIMESTAMP}, </if> <if test="operator != null"> `operator` = #{operator,jdbcType=BIGINT}, </if> <if test="result != null"> `result` = #{result,jdbcType=TINYINT}, </if> <if test="resultTime != null"> result_time = #{resultTime,jdbcType=TIMESTAMP}, </if> <if test="resultText != null"> result_text = #{resultText,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, </if> </set> where id = #{id,jdbcType=BIGINT} </update> <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoRm.RmCommandHistory"> <!--@mbg.generated--> update rm_command_history set command_code = #{commandCode,jdbcType=VARCHAR}, command_name = #{commandName,jdbcType=VARCHAR}, rtuAddr = #{rtuaddr,jdbcType=VARCHAR}, protocol = #{protocol,jdbcType=VARCHAR}, command_type = #{commandType,jdbcType=VARCHAR}, callBack = #{callback,jdbcType=VARCHAR}, param = #{param,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, send_time = #{sendTime,jdbcType=TIMESTAMP}, `operator` = #{operator,jdbcType=BIGINT}, `result` = #{result,jdbcType=TINYINT}, result_time = #{resultTime,jdbcType=TIMESTAMP}, result_text = #{resultText,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler} where id = #{id,jdbcType=BIGINT} </update> </mapper> pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/test/CommandCtrl.java
@@ -3,9 +3,10 @@ import com.dy.common.mw.protocol.p206V202404.CodeV202404; import com.dy.common.mw.protocol.p206V202404.downVos.*; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @Author: liurunyu @@ -21,12 +22,13 @@ @GetMapping(path = "test") public BaseResponse<String> test() { //return this.connect() ;//连接通信中间件测试 return this.cdXY(CodeV202404.cd_30) ;//发送固定参数XY的命令 //return this.cdXY(CodeV202404.cd_30) ;//发送固定参数XY的命令 //return this.cd55(1) ; //return this.cd15() ; //return this.cd16() ; //return this.cd22() ; //return this.cd31() ; return this.cd10(); } /** pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerCtrl.java
@@ -244,4 +244,6 @@ String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20"); response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); } } pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerSv.java
@@ -2,10 +2,6 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.dy.common.mw.protocol.Command; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; import com.dy.common.webUtil.QueryResultVo; import com.dy.pipIrrGlobal.daoPr.PrControllerMapper; import com.dy.pipIrrGlobal.daoPr.PrIntakeControllerMapper; @@ -13,24 +9,16 @@ import com.dy.pipIrrGlobal.pojoPr.PrController; import com.dy.pipIrrGlobal.pojoPr.PrIntakeController; import com.dy.pipIrrGlobal.voPr.VoController; import com.dy.pipIrrProject.result.ProjectResultCode; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.common.utils.PojoUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; import static com.dy.common.mw.protocol.CommandType.innerCommand; /** * @author ZhuBaoMin pipIrr-platform/pipIrr-web/pipIrr-web-remote/pom.xml
@@ -2,6 +2,14 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <dependencies> <dependency> <groupId>com.dy</groupId> <artifactId>pipIrr-web-project</artifactId> <version>1.0.0</version> <scope>compile</scope> </dependency> </dependencies> <parent> <artifactId>pipIrr-web</artifactId> pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/PipIrrRemoteApplication.java
@@ -18,7 +18,7 @@ }) } ) @MapperScan(basePackages={"com.dy.pipIrrGlobal.daoBa"}) @MapperScan(basePackages={"com.dy.pipIrrGlobal.daoRm", "com.dy.pipIrrGlobal.daoPr"}) public class PipIrrRemoteApplication { public static void main(String[] args) { pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/ComSupport.java
New file @@ -0,0 +1,143 @@ package com.dy.pipIrrRemote.common; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.dy.common.mw.protocol.Command; import com.dy.common.mw.protocol.CommandType; import com.dy.common.mw.protocol.p206V202404.CodeV202404; import com.dy.common.mw.protocol.p206V202404.ProtocolConstantV206V202404; import com.dy.common.mw.protocol.p206V202404.downVos.ComCdXyVo; import com.dy.common.webUtil.BaseResponse; import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; import java.util.Date; /** * @author ZhuBaoMin * @date 2024-05-21 15:30 * @LastEditTime 2024-05-21 15:30 * @Description */ //@RequiredArgsConstructor public class ComSupport { //@NotNull //private final CommandSv commandSv; protected static String mwUrlTest = "http://127.0.0.1:8070/rtuMw/com/test" ; protected static String mwUrlSendCom = "http://127.0.0.1:8070/rtuMw/com/send" ; //protected static String rtuAddr = "37142501020100215" ; protected static String rtuResultSendWebUrl = "http://127.0.0.1:8081/remote/comRes/receive" ; protected static String controllerType = "57" ;//控制器类型 protected static Integer projectNo = 10 ;//项目编码 protected static String icCardAddr = "04BEA5BB" ;//IC卡地址 protected static String icCardNo = "37142501020500001" ;//IC卡编号(用户卡序列号) protected String protocolName = ProtocolConstantV206V202404.protocolName; protected String commandTypeInner = CommandType.innerCommand; protected String commandTypeOuter = CommandType.outerCommand; @Autowired private RestTemplate restTemplate; protected ComCdXyVo comCdXyVo(){ ComCdXyVo comVo = new ComCdXyVo() ; comVo.controllerType = controllerType ; comVo.projectNo = projectNo ; return comVo ; } /** * 创建命令日志对象 * @param commandCode 功能码 * @param rtuAddr 阀控器地址 * @param param 参数数据 * @param operator 操作员 * @return 零零日志对象 */ protected RmCommandHistory getComHistory(String commandCode, String rtuAddr, Object param, Long operator ) { RmCommandHistory rmCommandHistory = new RmCommandHistory(); rmCommandHistory.setCommandCode(commandCode); rmCommandHistory.setCommandName(CodeV202404.getCodeName(commandCode)); rmCommandHistory.setRtuaddr(rtuAddr); rmCommandHistory.setProtocol(protocolName); rmCommandHistory.setCommandType(commandTypeOuter); rmCommandHistory.setCallback(rtuResultSendWebUrl); rmCommandHistory.setParam((JSONObject) JSON.toJSON(param)); rmCommandHistory.setSendTime(new Date()); rmCommandHistory.setOperator(operator); return rmCommandHistory; } /** * 构造命令对象 * @param comId 命令ID * @param commandCode 功能码 * @param rtuAddr RTU地址 * @param param 参数数据 * @return 构造好的命令对象 */ protected Command command(String comId, String commandCode, String rtuAddr, Object param){ Command com = new Command() ; com.id = comId==null?Command.defaultId:(comId.trim().equals("")?Command.defaultId:comId); com.code = commandCode ; com.rtuAddr = rtuAddr ; com.protocol = protocolName; com.type = commandTypeOuter; com.rtuResultSendWebUrl = rtuResultSendWebUrl ; com.param = param ; return com ; } /** * 连接通信中间件测试 * @return */ protected BaseResponse sendTest(){ String url = UriComponentsBuilder.fromUriString(mwUrlTest) .build() .toUriString(); HttpHeaders headers = new HttpHeaders(); HttpEntity<?> httpEntity = new HttpEntity<>(headers); ResponseEntity<BaseResponse> response = null; try { // 通过Get方式调用接口 response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, BaseResponse.class); } catch (Exception e) { e.printStackTrace(); } return response.getBody(); } /** * 发送命令 * @return */ protected BaseResponse sendCom2Mw(Command com){ String url = UriComponentsBuilder.fromUriString(mwUrlSendCom) .build() .toUriString(); HttpHeaders headers = new HttpHeaders(); HttpEntity<Command> httpEntity = new HttpEntity<>(com, headers); ResponseEntity<BaseResponse> response = null; try { // 通过Post方式调用接口 response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, BaseResponse.class); } catch (Exception e) { e.printStackTrace(); } return response.getBody(); } } pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/CommandSv.java
New file @@ -0,0 +1,51 @@ package com.dy.pipIrrRemote.common; import com.dy.pipIrrGlobal.daoPr.PrControllerMapper; import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper; import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; /** * @author ZhuBaoMin * @date 2024-05-21 17:14 * @LastEditTime 2024-05-21 17:14 * @Description 命令日志服务类 */ @Slf4j @Service @RequiredArgsConstructor public class CommandSv { private final RmCommandHistoryMapper rmCommandHistoryMapper; private final PrControllerMapper prControllerMapper; /** * 根据取水口ID获取阀控器地址 * @param intakeId 取水口ID * @return 阀控器地址 */ public String getRtuAddrByIntakeId(Long intakeId) { return prControllerMapper.getRtuAddrByIntakeId(intakeId); } /** * 添加命令日志 * @param po 命令日志对象 * @return 字符串类型的主键 */ public String insert(RmCommandHistory po) { rmCommandHistoryMapper.insert(po); return (po.getId()).toString(); } /** * 修改命令日志信息 * @param po 命令日志对象 * @return 影响记录数量 */ public Integer update(RmCommandHistory po) { return rmCommandHistoryMapper.updateByPrimaryKeySelective(po); } } pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/result/RemoteResultCode.java
@@ -17,7 +17,12 @@ */ DIVIDE_FAIL(10001, "分水房添加失败"), DELETE_DIVIDE_FAIL(10001, "分水房删除失败"), NO_DIVIDES(10001, "无符合条件的分水房记录"); NO_DIVIDES(10001, "无符合条件的分水房记录"), /** * RTU */ RTU_ADDR_CANNOT_BE_NULL(20001, "阀控器地址不能为空"); private final Integer code; private final String message; pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtu/CommandResultCtrl.java
New file @@ -0,0 +1,29 @@ package com.dy.pipIrrRemote.rtu; import com.dy.common.mw.protocol.Data; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; import lombok.extern.slf4j.Slf4j; 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; /** * @author ZhuBaoMin * @date 2024-05-23 8:19 * @LastEditTime 2024-05-23 8:19 * @Description */ @Slf4j @RestController @RequestMapping(path="comRes") public class CommandResultCtrl { @PostMapping(path = "receive", consumes = MediaType.APPLICATION_JSON_VALUE) public BaseResponse<String> receive(@RequestBody Data data) { log.info(data.toString()) ; return BaseResponseUtils.buildSuccess("ok"); } } pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtu/RtuCtrl.java
New file @@ -0,0 +1,116 @@ package com.dy.pipIrrRemote.rtu; import com.dy.common.aop.SsoAop; import com.dy.common.mw.protocol.Command; import com.dy.common.mw.protocol.p206V202404.CodeV202404; import com.dy.common.mw.protocol.p206V202404.downVos.ComCd10Vo; import com.dy.common.mw.protocol.p206V202404.downVos.ComCdXyVo; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory; import com.dy.pipIrrRemote.common.ComSupport; import com.dy.pipIrrRemote.common.CommandSv; import com.dy.pipIrrRemote.result.RemoteResultCode; import com.dy.pipIrrRemote.rtu.dto.Addr; import com.dy.pipIrrRemote.rtu.dto.DtoBase; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.BindingResult; 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.Objects; /** * @author ZhuBaoMin * @date 2024-05-21 14:31 * @LastEditTime 2024-05-21 14:31 * @Description 设备终端控制类 */ @Slf4j @RestController @RequestMapping(path="rtu") @RequiredArgsConstructor public class RtuCtrl extends ComSupport { private final CommandSv commandSv; protected static String controllerType = "57"; /** * 设置设备终端地址 * @param addr 设置设备终端地址传入对象 * @param bindingResult * @return */ @PostMapping(path = "set_addr", consumes = MediaType.APPLICATION_JSON_VALUE) @Transactional(rollbackFor = Exception.class) @SsoAop() public BaseResponse<Boolean> setAddr(@RequestBody @Valid Addr addr, BindingResult bindingResult) { if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } String commandCode = CodeV202404.cd_10; Long intakeId = addr.getIntakeId(); String newRtuAddr = addr.getNewRtuAddr(); Long operator = addr.getOperator(); // 取水口ID换阀控器地址 String rtuAddr = commandSv.getRtuAddrByIntakeId(intakeId); if(rtuAddr == null || rtuAddr.length() == 0) { return BaseResponseUtils.buildError(RemoteResultCode.RTU_ADDR_CANNOT_BE_NULL.getMessage()); } // 创建视图 ComCd10Vo param = new ComCd10Vo() ; param.controllerType = controllerType; param.projectNo = Integer.parseInt(commandCode); param.rtuNewAddr = newRtuAddr; // 创建命令日志对象并添加到数据库中 RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, param, operator); String comId = commandSv.insert(rmCommandHistory); // 构造命令 Command com = command(comId, commandCode, rtuAddr, param); return sendCom2Mw(com); } @PostMapping(path = "clear_usage_record", consumes = MediaType.APPLICATION_JSON_VALUE) @Transactional(rollbackFor = Exception.class) @SsoAop() public BaseResponse<Boolean> clearUsageRecord(@RequestBody @Valid DtoBase po, BindingResult bindingResult) { if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } String commandCode = CodeV202404.cd_97; Long intakeId = po.getIntakeId(); Long operator = po.getOperator(); // 取水口ID换阀控器地址 String rtuAddr = commandSv.getRtuAddrByIntakeId(intakeId); if(rtuAddr == null || rtuAddr.length() == 0) { return BaseResponseUtils.buildError(RemoteResultCode.RTU_ADDR_CANNOT_BE_NULL.getMessage()); } // 创建视图 ComCdXyVo param = new ComCdXyVo(); param.controllerType = controllerType; param.projectNo = Integer.parseInt(commandCode); // 创建命令日志对象并添加到数据库中 RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, param, operator); String comId = commandSv.insert(rmCommandHistory); // 构造命令 Command com = command(comId, commandCode, rtuAddr, param); return sendCom2Mw(com); } } pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtu/dto/Addr.java
New file @@ -0,0 +1,22 @@ package com.dy.pipIrrRemote.rtu.dto; import jakarta.validation.constraints.NotBlank; import lombok.Data; /** * @author ZhuBaoMin * @date 2024-05-22 16:56 * @LastEditTime 2024-05-22 16:56 * @Description */ @Data public class Addr extends DtoBase { public static final long serialVersionUID = 202405221656001L; /** * 新的阀控器地址 */ @NotBlank(message = "新的阀控器地址不能为空") private String newRtuAddr; } pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtu/dto/DtoBase.java
New file @@ -0,0 +1,28 @@ package com.dy.pipIrrRemote.rtu.dto; import jakarta.validation.constraints.NotNull; import lombok.Data; /** * @author ZhuBaoMin * @date 2024-05-22 16:54 * @LastEditTime 2024-05-22 16:54 * @Description */ @Data public class DtoBase { public static final long serialVersionUID = 202405221655001L; /** * 取水口ID */ @NotNull(message = "取水口不能为空") private Long intakeId; /** * 操作人 */ @NotNull(message = "操作人不能为空") private Long operator; }