pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voPr/VoController.java
@@ -51,8 +51,24 @@ @ColumnWidth(30) private Date findDt; @Schema(title = "在线状态") @ExcelProperty("在线状态") @ColumnWidth(6) private String onlineState; // @Schema(title = "在线状态") // @ExcelProperty("在线状态") // @ColumnWidth(6) // private String onlineState; /** * 是否在线 */ private Boolean isOnLine; @Schema(title = "通讯协议") @ExcelProperty("通讯协议") @ColumnWidth(10) private String protocol; @Schema(title = "备注") @ExcelProperty("备注") @ColumnWidth(10) private String remarks; } pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrControllerMapper.xml
@@ -168,19 +168,28 @@ SELECT COUNT(*) AS recordCount FROM pr_controller con LEFT JOIN pr_intake_controller ic ON ic.controllerId = con.id INNER JOIN pr_intake inta ON con.intakeId = inta.id LEFT JOIN pr_intake_controller ic ON ic.controllerId = con.id INNER JOIN pr_intake inta ON con.intakeId = inta.id left JOIN JSON_TABLE( <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',--> #{onLineMap}, '$[*]' COLUMNS( rtuAddr VARCHAR(20) PATH '$.rtuAddr', isOnLine BOOLEAN PATH '$.isOnLine' ) ) rtus ON con.rtuAddr = rtus.rtuAddr <where> AND con.deleted = 0 <if test = "id != null and id > 0"> AND con.id = ${id} </if> <if test = "rtuAddr != null and rtuAddr !=''"> AND con.rtuAddr like CONCAT('%',#{rtuAddr},'%') </if> <if test="isOnLine != null and isOnLine !='' "> AND rtus.isOnLine = #{isOnLine} </if> <if test = "bindNumber != null and bindNumber > 0"> AND (SELECT COUNT(*) FROM pr_intake_controller WHERE controllerId = con.id AND intakeId = inta.id AND operateType = 1) = ${bindNumber} </if> @@ -193,23 +202,34 @@ CAST(con.id AS char) AS id, con.rtuAddr AS rtuAddr, inta.name AS intakeName, "在线" AS onlineState, con.protocol, inta.remarks, rtus.isOnLine, (SELECT COUNT(*) FROM pr_intake_controller WHERE controllerId = con.id AND intakeId = inta.id AND operateType = 1) AS bindNumber, con.findDt AS findDt FROM pr_controller con LEFT JOIN pr_intake_controller ic ON ic.controllerId = con.id INNER JOIN pr_intake inta ON con.intakeId = inta.id left JOIN JSON_TABLE( <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',--> #{onLineMap}, '$[*]' COLUMNS( rtuAddr VARCHAR(20) PATH '$.rtuAddr', isOnLine BOOLEAN PATH '$.isOnLine' ) ) rtus ON con.rtuAddr = rtus.rtuAddr <where> AND con.deleted = 0 <if test = "id != null and id > 0"> AND con.id = ${id} </if> <if test = "rtuAddr != null and rtuAddr !=''"> AND con.rtuAddr like CONCAT('%',#{rtuAddr},'%') </if> <if test="isOnLine != null and isOnLine !='' "> AND rtus.isOnLine = #{isOnLine} </if> <if test = "bindNumber != null and bindNumber > 0"> AND (SELECT COUNT(*) FROM pr_intake_controller WHERE controllerId = con.id AND intakeId = inta.id AND operateType = 1) = ${bindNumber} </if> pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerCtrl.java
@@ -76,7 +76,7 @@ } //return BaseResponseUtils.buildSuccess(res); } catch (Exception e) { log.error("获取开卡记录异常", e); log.error("获取控制器记录异常", e); return BaseResponseUtils.buildException(e.getMessage()); } } pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerSv.java
@@ -2,6 +2,9 @@ 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.QueryResultVo; import com.dy.pipIrrGlobal.daoPr.PrControllerMapper; import com.dy.pipIrrGlobal.daoPr.PrIntakeControllerMapper; @@ -9,16 +12,19 @@ import com.dy.pipIrrGlobal.pojoPr.PrController; import com.dy.pipIrrGlobal.pojoPr.PrIntakeController; import com.dy.pipIrrGlobal.voPr.VoController; import com.dy.pipIrrGlobal.voPr.VoOnLineIntake; 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.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.*; /** * @author ZhuBaoMin @@ -42,6 +48,8 @@ @Autowired private RestTemplate restTemplate; protected static String mwUrlSendCom = "http://127.0.0.1:8070/rtuMw/com/send"; /** * 根据指定获取控制器记录 @@ -50,18 +58,42 @@ * @return */ public QueryResultVo<List<VoController>> getControllers(QueryVo queryVo) { Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); Long itemTotal = prControllerMapper.getRecordCount(params); Command com = new Command(); com.id = Command.defaultId; com.code = "LCD0001"; com.type = "innerCommand"; QueryResultVo<List<VoController>> rsVo = new QueryResultVo<>(); rsVo.pageSize = queryVo.pageSize; rsVo.pageCurr = queryVo.pageCurr; JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); rsVo.calculateAndSet(itemTotal, params); rsVo.obj = prControllerMapper.getControllers(params); if (response != null && response.getString("code").equals("0001")) { JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap"); HashMap<String, Boolean> onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class); return rsVo; JSONArray jsonArray = new JSONArray(); for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) { JSONObject jsonObject = new JSONObject(); jsonObject.put("rtuAddr", entry.getKey()); jsonObject.put("isOnLine", entry.getValue()); jsonArray.add(jsonObject); } queryVo.setOnLineMap(jsonArray.toJSONString()); Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); Long itemTotal = prControllerMapper.getRecordCount(params); QueryResultVo<List<VoController>> rsVo = new QueryResultVo<>(); rsVo.pageSize = queryVo.pageSize; rsVo.pageCurr = queryVo.pageCurr; rsVo.calculateAndSet(itemTotal, params); rsVo.obj = prControllerMapper.getControllers(params); return rsVo; } else { QueryResultVo<List<VoController>> rsVo = new QueryResultVo<>(); return rsVo; } } /** @@ -72,7 +104,7 @@ */ public Integer addController(PrController po) { int rows = prControllerMapper.insert(po); if(rows == 0) { if (rows == 0) { return 0; } PrIntakeController addPrIntakeController = new PrIntakeController(); @@ -83,10 +115,10 @@ addPrIntakeController.setOperatedt(po.getOperateDt()); addPrIntakeController.setRemarks("绑定"); int rec = prIntakeControllerMapper.insert(addPrIntakeController); if(rec == 0) { if (rec == 0) { return 0; } return 1 ; return 1; } /** @@ -168,7 +200,8 @@ /** * 根据控制器编号物理删除控制 *2024-6-7 * 2024-6-7 * * @param controllerId * @return */ @@ -178,11 +211,34 @@ /** * 根据主键查询控制器列表 *2024-6-7 * 2024-6-7 * * @param controllerId * @return */ public PrController getByControllerId(Long controllerId) { return prControllerMapper.selectByPrimaryKey(controllerId); } /** * 发送命令 * * @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-project/src/main/java/com/dy/pipIrrProject/controller/QueryVo.java
@@ -2,6 +2,8 @@ import com.dy.common.webUtil.QueryConditionVo; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import lombok.*; /** @@ -29,9 +31,21 @@ @Schema(description = "控制器地址") private String rtuAddr; @Schema(description = "在线状态") public Integer onlineState; // @Schema(description = "在线状态") // public Integer onlineState; @Schema(description = "绑定数量") public Integer bindNumber; /** * 中间件返回的RTU在线情况对象数组 */ private String onLineMap; /** * 是否在线 */ @Max(value = 1,message = "是否在线仅允许为真或假") @Min(value = 0,message = "是否在线仅允许为真或假") private Boolean isOnLine; }