From 8d2b573ced32e6ca6fab7c1dc45e1fa108030ba1 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期三, 28 八月 2024 17:21:23 +0800 Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV --- pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerSv.java | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 100 insertions(+), 17 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerSv.java index 32ae257..edce345 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerSv.java +++ b/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,49 @@ * @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 = null; + try { + response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); + }catch (Exception e) { + QueryResultVo<List<VoController>> rsVo = new QueryResultVo<>(); + return rsVo; + } - rsVo.calculateAndSet(itemTotal, params); - rsVo.obj = prControllerMapper.getControllers(params); - return rsVo; + 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); + + 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 +111,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 +122,10 @@ addPrIntakeController.setOperatedt(po.getOperateDt()); addPrIntakeController.setRemarks("缁戝畾"); int rec = prIntakeControllerMapper.insert(addPrIntakeController); - if(rec == 0) { + if (rec == 0) { return 0; } - return 1 ; + return 1; } /** @@ -100,13 +139,13 @@ } /** - * 鏍规嵁鎺у埗鍣ㄧ紪鍙烽�昏緫鍒犻櫎鎺у埗 + * 鏍规嵁鎺у埗鍣ㄧ紪鍙风墿鐞嗗垹闄ゆ帶鍒� * * @param controllerId * @return */ public Integer deleteControllerById(Long controllerId) { - return prControllerMapper.deleteControllerById(controllerId); + return prControllerMapper.deleteByPrimaryKey(controllerId); } /** @@ -165,4 +204,48 @@ } return array; } + + /** + * 鏍规嵁鎺у埗鍣ㄧ紪鍙风墿鐞嗗垹闄ゆ帶鍒� + * 2024-6-7 + * + * @param controllerId + * @return + */ + public Integer deleteControllerByIdTwo(Long controllerId) { + return prControllerMapper.deleteByPrimaryKey(controllerId); + } + + /** + * 鏍规嵁涓婚敭鏌ヨ鎺у埗鍣ㄥ垪琛� + * 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(); + } } -- Gitblit v1.8.0