From cd7fd2ea35de966cfd1c6f3038e593097d7a6dec Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期四, 03 七月 2025 11:26:46 +0800 Subject: [PATCH] 轮灌组PC端接口 --- /dev/null | 109 ---------- pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/command/CommandSv.java | 3 pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationSv.java | 176 +++++++++++++++++ pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanCtrl.java | 103 +++++++++ pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationCtrl.java | 45 ++++ pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/qo/QoIrrigatePlan.java | 41 ++++ pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanSv.java | 120 +++++++++++ 7 files changed, 475 insertions(+), 122 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/command/CommandSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/command/CommandSv.java index 9d24787..9a32004 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/command/CommandSv.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/command/CommandSv.java @@ -40,8 +40,7 @@ import com.dy.pipIrrIrrigate.command.dto.AutomaticClose; import com.dy.pipIrrIrrigate.command.dto.ValveClose; import com.dy.pipIrrIrrigate.command.dto.ValveOpen; -import com.dy.pipIrrIrrigate.irrigatePlan.IrrigatePlanSv; -import com.dy.pipIrrIrrigate.irrigatePlan.IrrigationSv; +import com.dy.pipIrrIrrigate.irrigation.IrrigationSv; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanCtrl.java index 40fbe97..f6425a2 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanCtrl.java @@ -3,6 +3,10 @@ import com.dy.common.aop.SsoAop; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryConditionVo; +import com.dy.common.webUtil.QueryResultVo; +import com.dy.pipIrrGlobal.voIr.VoPlanDetails; +import com.dy.pipIrrGlobal.voIr.VoPlans; import com.dy.pipIrrIrrigate.irrigatePlan.dto.IrrigatePlan; import com.dy.pipIrrIrrigate.irrigatePlan.dto.PlanSimple; import jakarta.validation.Valid; @@ -10,11 +14,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; 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 org.springframework.web.bind.annotation.*; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -114,4 +116,97 @@ } return BaseResponseUtils.buildSuccess() ; } + + /** + * 鑾峰彇鏈畬鎴愮殑璁″垝鍒楄〃锛岀亴婧夋ā鍧楄鍒掑垪琛ㄩ〉浣跨敤 + * @return + */ + @GetMapping(path = "/getNotCompletePlans") + @SsoAop() + public BaseResponse<List<VoPlans>> getNotCompletePlans() { + try { + List<VoPlans> res = irrigatePlanSv.getNotCompletePlans(); + return BaseResponseUtils.buildSuccess(res); + } catch (Exception e) { + log.error("鑾峰彇鏈畬鐨勮鍒掑紓甯�", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + /** + * 鑾峰彇宸插畬鎴愮殑璁″垝鍒楄〃锛岀亴婧夋ā鍧楄鍒掑垪琛ㄩ〉浣跨敤 + * @return + */ + @GetMapping(path = "/getCompletedPlans") + @SsoAop() + public BaseResponse<QueryResultVo<List<VoPlans>>> getCompletedPlans(QueryConditionVo qo) { + try { + return BaseResponseUtils.buildSuccess(irrigatePlanSv.getCompletedPlans(qo)); + } catch (Exception e) { + log.error("鑾峰彇椤圭洰璁板綍寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + /** + * 鏍规嵁璁″垝ID鑾峰彇璁″垝鍙戝竷缁撴灉 + * @param planId + * @return + */ + @GetMapping(path = "/getPublishResults") + @SsoAop() + public BaseResponse<VoPlanDetails> getPublishResults(@RequestParam Long planId) { + if(planId == null) { + return BaseResponseUtils.buildErrorMsg("璁″垝ID涓嶈兘涓虹┖"); + } + + try { + VoPlanDetails res = irrigatePlanSv.getPublishResults(planId); + return BaseResponseUtils.buildSuccess(res); + } catch (Exception e) { + log.error("鑾峰彇璁″垝鍙戝竷缁撴灉寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + /** + * 鏍规嵁璁″垝ID鑾峰彇璁″垝缁堟鎿嶄綔缁撴灉 + * @param planId + * @return + */ + @GetMapping(path = "/getTerminateResults") + @SsoAop() + public BaseResponse<VoPlanDetails> getTerminateResults(@RequestParam Long planId) { + if(planId == null) { + return BaseResponseUtils.buildErrorMsg("璁″垝ID涓嶈兘涓虹┖"); + } + + try { + VoPlanDetails res = irrigatePlanSv.getTerminateResults(planId); + return BaseResponseUtils.buildSuccess(res); + } catch (Exception e) { + log.error("鑾峰彇璁″垝鍙戝竷缁撴灉寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + /** + * 鏍规嵁璁″垝ID鑾峰彇璁″垝鏈�鏂扮姸鎬� + * @param planId + * @return + */ + @GetMapping(path = "/getPlanLatestState") + @SsoAop() + public BaseResponse<Integer> getPlanLatestState(@RequestParam Long planId) { + if(planId == null) { + return BaseResponseUtils.buildErrorMsg("璁″垝ID涓嶈兘涓虹┖"); + } + + try { + return BaseResponseUtils.buildSuccess(irrigatePlanSv.getPlanLatestState(planId)); + } catch (Exception e) { + log.error("鑾峰彇鏈畬鐨勮鍒掑紓甯�", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanSv.java index 9f05099..6e43aca 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanSv.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanSv.java @@ -7,6 +7,8 @@ import com.dy.common.mw.protocol.CommandType; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryConditionVo; +import com.dy.common.webUtil.QueryResultVo; import com.dy.pipIrrGlobal.daoIr.*; import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper; import com.dy.pipIrrGlobal.pojoIr.IrIrrigatePlan; @@ -14,9 +16,7 @@ import com.dy.pipIrrGlobal.pojoIr.IrPlanOperate; import com.dy.pipIrrGlobal.pojoIr.IrPlanSchedule; import com.dy.pipIrrGlobal.rtuMw.CodeLocal; -import com.dy.pipIrrGlobal.voIr.VoIrrigateSchedule; -import com.dy.pipIrrGlobal.voIr.VoPlanSimple; -import com.dy.pipIrrGlobal.voIr.VoToTerminateIntakes; +import com.dy.pipIrrGlobal.voIr.*; import com.dy.pipIrrGlobal.voRm.VoIntakeVc; import com.dy.pipIrrIrrigate.command.CommandSv; import com.dy.pipIrrIrrigate.command.dto.AutomaticClose; @@ -26,6 +26,7 @@ import com.dy.pipIrrIrrigate.irrigatePlan.dto.PlanSimple; import com.dy.pipIrrIrrigate.irrigatePlan.enums.OperateTypeENUM; import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.common.utils.PojoUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; @@ -42,10 +43,7 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author ZhuBaoMin @@ -80,6 +78,9 @@ @Autowired private RmCommandHistoryMapper rmdCommandHistoryMapper; + + @Autowired + private IrIrrigateGroupMapper irIrrigateGroupMapper; protected String comSendUrl; private String key_mw = "comSendUrl"; @@ -647,4 +648,109 @@ map.put("msg", "缁堟鐏屾簤璁″垝鎴愬姛"); return map; } + + /** + * 鑾峰彇鏈畬鎴愮殑璁″垝鍒楄〃锛岀亴婧夋ā鍧楄鍒掑垪琛ㄩ〉浣跨敤 + * + * @return + */ + public List<VoPlans> getNotCompletePlans() { + return irrigatePlanMapper.getNotCompletePlans(); + } + + /** + * 鑾峰彇宸插畬鎴愮殑璁″垝鍒楄〃锛岀亴婧夋ā鍧楄鍒掑垪琛ㄩ〉浣跨敤 + * + * @return + */ + public QueryResultVo<List<VoPlans>> getCompletedPlans(QueryConditionVo queryVo) { + Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); + + Long itemTotal = (long) irrigatePlanMapper.getCompletedPlansCount(params); + QueryResultVo<List<VoPlans>> rsVo = new QueryResultVo<>(); + rsVo.pageSize = queryVo.pageSize; + rsVo.pageCurr = queryVo.pageCurr; + + rsVo.calculateAndSet(itemTotal, params); + rsVo.obj = irrigatePlanMapper.getCompletedPlans(params); + + return rsVo; + } + + /** + * 鏍规嵁璁″垝ID鑾峰彇璁″垝鍙戝竷缁撴灉 + * + * @param planId + * @return + */ + public VoPlanDetails getPublishResults(Long planId) { + VoPlanDetails planDetails = irrigatePlanMapper.getPlanDetails(planId); + if (planDetails == null) { + return null; + } + Integer failureCount = Optional.ofNullable(irIntakeOperateMapper.getFailureCount(planId)).orElse(0); + planDetails.setFailureCount(failureCount); + + Date terminateTime = Optional.ofNullable(irPlanOperateMapper.getTerminateTime(planId)).orElse(null); + + List<VoGroupResult> groupResults = irIrrigateGroupMapper.getGroupResult(planId); + if (groupResults == null || groupResults.size() == 0) { + return null; + } + + for (VoGroupResult groupResult : groupResults) { + List<VoIntakeResult> intakeResults = irIntakeOperateMapper.getIntakeResult(planId, groupResult.getGroupId()); + if (intakeResults != null) { + groupResult.setPublishResult(intakeResults); + } + } + + planDetails.setGroups(groupResults); + return planDetails; + + } + + /** + * 鏍规嵁璁″垝ID鑾峰彇璁″垝缁堟鎿嶄綔缁撴灉 + * + * @param planId + * @return + */ + public VoPlanDetails getTerminateResults(Long planId) { + // 鑾峰彇璁″垝缁堟鏃堕棿 + Date terminateTime = Optional.ofNullable(irPlanOperateMapper.getTerminateTime(planId)).orElse(null); + + VoPlanDetails planDetails = irrigatePlanMapper.getPlanDetails_terminate(planId, terminateTime); + if (planDetails == null) { + return null; + } + Integer failureCount = Optional.ofNullable(irIntakeOperateMapper.getFailureCount(planId)).orElse(0); + planDetails.setFailureCount(failureCount); + + List<VoGroupResult> groupResults = irIrrigateGroupMapper.getGroupResult_terminate(planId, terminateTime); + if (groupResults == null || groupResults.size() == 0) { + return null; + } + + for (VoGroupResult groupResult : groupResults) { + List<VoIntakeResult> intakeResults = irIntakeOperateMapper.getIntakeResult(planId, groupResult.getGroupId()); + if (intakeResults != null) { + groupResult.setPublishResult(intakeResults); + } + } + + planDetails.setGroups(groupResults); + return planDetails; + + } + + /** + * 鏍规嵁璁″垝ID鑾峰彇璁″垝鏈�鏂扮姸鎬� + * + * @param planId + * @return + */ + public Integer getPlanLatestState(Long planId) { + return irrigatePlanMapper.getPlanLatestState(planId); + } } \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigationSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigationSv.java deleted file mode 100644 index 3f1d0f4..0000000 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigationSv.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.dy.pipIrrIrrigate.irrigatePlan; - -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONObject; -import com.dy.common.multiDataSource.DataSourceContext; -import com.dy.common.mw.protocol.Command; -import com.dy.common.mw.protocol.CommandType; -import com.dy.common.webUtil.BaseResponse; -import com.dy.common.webUtil.BaseResponseUtils; -import com.dy.pipIrrGlobal.rtuMw.CodeLocal; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -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; - -/** - * @author ZhuBaoMin - * @date 2025-07-02 11:08 - * @LastEditTime 2025-07-02 11:08 - * @Description - */ - -@Slf4j -@Service -public class IrrigationSv { - @Autowired - private Environment env; - - @Autowired - private RestTemplate restTemplate; - - private static final String pro_mw = "mw"; - private String key_mw = "comSendUrl"; - - public Boolean getOnlineStatus(String rtuAdd) { - Command com = new Command(); - com.id = Command.defaultId; - com.code = CodeLocal.onLinePart; - com.type = CommandType.innerCommand; - com.setRtuAddr(rtuAdd); - com.setParam(rtuAdd); - JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); - - if (response == null || !response.getString("code").equals("0001") || response.getJSONObject("content").getJSONObject("attachment").size() == 0) { - return false; - } - - if(response.getJSONObject("content").getJSONObject("attachment").getBoolean(rtuAdd)) { - return true; - } - else { - return false; - } - } - - public Boolean getOpenCloseStatus(String rtuAdd) { - Command com = new Command(); - com.id = Command.defaultId; - com.code = CodeLocal.oneRtuStates; - com.type = CommandType.innerCommand; - com.setRtuAddr(rtuAdd); - com.setParam(rtuAdd); - JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); - - if (response == null || !response.getString("code").equals("0001") || response.getJSONObject("content").getJSONObject("attachment") == null) { - return false; - } - - // if(response.getJSONObject("content").getJSONObject("attachment").get("valveOpenTrueCloseFalse").equals("true")) { - if(response.getJSONObject("content").getJSONObject("attachment").getBoolean("valveOpenTrueCloseFalse")) { - return true; - } - else { - return false; - } - } - - /** - * 鍙戦�佸懡浠� - * - * @return - */ - protected BaseResponse sendCom2Mw(Command com) { - String url = UriComponentsBuilder.fromUriString(env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + key_mw)) - .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(); - } - - if(response == null) { - return BaseResponseUtils.buildErrorMsg("涓棿浠惰皟鐢ㄥけ璐�"); - } - - return response.getBody(); - } -} diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/qo/QoIrrigatePlan.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/qo/QoIrrigatePlan.java new file mode 100644 index 0000000..679ddd8 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/qo/QoIrrigatePlan.java @@ -0,0 +1,41 @@ +package com.dy.pipIrrIrrigate.irrigatePlan.qo; + +import com.dy.common.webUtil.QueryConditionVo; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @author ZhuBaoMin + * @date 2025-07-03 10:43 + * @LastEditTime 2025-07-03 10:43 + * @Description 鐏屾簤璁″垝鏌ヨ瀵硅薄 + */ + +@Data +@EqualsAndHashCode(callSuper = false) +public class QoIrrigatePlan extends QueryConditionVo { + /** + * 椤圭洰鍚嶇О + */ + private String projectName; + + /** + * 璁″垝鍚嶇О + */ + private String planName; + + /** + * 璁″垝鍚姩妯″紡锛�1-鎵嬪姩鍚姩锛�2-鑷姩鍚姩 + */ + private Byte startupMode; + + /** + * 璁″垝鐘舵�侊紱1-鑽夌锛�2-宸插彂甯� + */ + private Byte planState; + + /** + * 鎵ц鐘舵�侊紱1-鏈墽琛岋紝2-鎵ц涓紝3-宸叉殏鍋滐紝4-宸茬粓姝紝5-宸插畬鎴� + */ + private Byte executingState; +} diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationCtrl.java new file mode 100644 index 0000000..03549ee --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationCtrl.java @@ -0,0 +1,45 @@ +package com.dy.pipIrrIrrigate.irrigation; + +import com.dy.common.webUtil.BaseResponse; +import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.pipIrrGlobal.voIr.VoGroupIntakes; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author ZhuBaoMin + * @date 2025-07-03 10:58 + * @LastEditTime 2025-07-03 10:58 + * @Description + */ + +@Slf4j +@RestController +@RequestMapping(path = "irrigation") +@RequiredArgsConstructor +public class IrrigationCtrl { + private final IrrigationSv irrigationSv; + + /** + * 鏍规嵁杞亴缁処D鑾峰彇杞亴缁勮鎯� + * @param groupId + * @return + */ + @GetMapping(path = "/getGroupDetails") + public BaseResponse<VoGroupIntakes> getGroupDetails(@RequestParam Long groupId) { + if(groupId == null) { + return BaseResponseUtils.buildErrorMsg("杞亴缁処D涓嶈兘涓虹┖"); + } + + try { + return BaseResponseUtils.buildSuccess(irrigationSv.getGroupDetails(groupId).get("content")); + } catch (Exception e) { + log.error("鑾峰彇杞亴缁勮鎯呭紓甯�", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } +} diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationSv.java new file mode 100644 index 0000000..f6788f1 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationSv.java @@ -0,0 +1,176 @@ +package com.dy.pipIrrIrrigate.irrigation; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.dy.common.multiDataSource.DataSourceContext; +import com.dy.common.mw.protocol.Command; +import com.dy.common.mw.protocol.CommandType; +import com.dy.common.webUtil.BaseResponse; +import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.pipIrrGlobal.daoIr.IrIrrigateGroupMapper; +import com.dy.pipIrrGlobal.rtuMw.CodeLocal; +import com.dy.pipIrrGlobal.voIr.VoGroupIntakes; +import com.dy.pipIrrGlobal.voIr.VoIntake; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +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.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author ZhuBaoMin + * @date 2025-07-02 11:08 + * @LastEditTime 2025-07-02 11:08 + * @Description + */ + +@Slf4j +@Service +public class IrrigationSv { + @Autowired + private IrIrrigateGroupMapper irIrrigateGroupMapper; + + @Autowired + private Environment env; + + @Autowired + private RestTemplate restTemplate; + + private static final String pro_mw = "mw"; + private String key_mw = "comSendUrl"; + + public Boolean getOnlineStatus(String rtuAdd) { + Command com = new Command(); + com.id = Command.defaultId; + com.code = CodeLocal.onLinePart; + com.type = CommandType.innerCommand; + com.setRtuAddr(rtuAdd); + com.setParam(rtuAdd); + JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); + + if (response == null || !response.getString("code").equals("0001") || response.getJSONObject("content").getJSONObject("attachment").size() == 0) { + return false; + } + + if(response.getJSONObject("content").getJSONObject("attachment").getBoolean(rtuAdd)) { + return true; + } + else { + return false; + } + } + + public Boolean getOpenCloseStatus(String rtuAdd) { + Command com = new Command(); + com.id = Command.defaultId; + com.code = CodeLocal.oneRtuStates; + com.type = CommandType.innerCommand; + com.setRtuAddr(rtuAdd); + com.setParam(rtuAdd); + JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); + + if (response == null || !response.getString("code").equals("0001") || response.getJSONObject("content").getJSONObject("attachment") == null) { + return false; + } + + // if(response.getJSONObject("content").getJSONObject("attachment").get("valveOpenTrueCloseFalse").equals("true")) { + if(response.getJSONObject("content").getJSONObject("attachment").getBoolean("valveOpenTrueCloseFalse")) { + return true; + } + else { + return false; + } + } + + /** + * 鍙戦�佸懡浠� + * + * @return + */ + protected BaseResponse sendCom2Mw(Command com) { + String url = UriComponentsBuilder.fromUriString(env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + key_mw)) + .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(); + } + + if(response == null) { + return BaseResponseUtils.buildErrorMsg("涓棿浠惰皟鐢ㄥけ璐�"); + } + + return response.getBody(); + } + + /** + * 鏍规嵁杞亴缁処D鑾峰彇杞亴缁勮鎯� + * @param groupId + * @return + */ + public Map getGroupDetails(Long groupId) { + try { + // 鐢熸垚椤圭洰淇℃伅鍙婅疆鐏岀粍淇℃伅 + VoGroupIntakes voGroupIntakes = new VoGroupIntakes(); + String projectName = ""; + String groupName = ""; + List<VoGroupIntakes> groupIntakes = irIrrigateGroupMapper.getGroupIntakes(groupId); + if (groupIntakes == null) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("msg", "杞亴缁勪笉瀛樺湪"); + map.put("content", null); + return map; + } + for(VoGroupIntakes groupIntake : groupIntakes) { + projectName = projectName + groupIntake.getProjectName() + "銆�"; + groupName = groupIntake.getGroupName(); + } + voGroupIntakes.setProjectName(projectName.substring(0, projectName.length() - 1)); + voGroupIntakes.setGroupName(groupName); + + // 琛ュ叏鍙栨按鍙d俊鎭紙鍦ㄧ嚎鎯呭喌锛� + List<VoIntake> intakes = irIrrigateGroupMapper.getGroupIntakesList(groupId); + if(intakes == null) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("msg", "璇ヨ疆鐏岀粍鏈粦瀹氬彇姘村彛"); + map.put("content", null); + return map; + } + for (VoIntake intake : intakes) { + Boolean isOnLine = getOnlineStatus(intake.getRtuAddr()); + intake.setIsOnLine(isOnLine); + Boolean isOpen = getOpenCloseStatus(intake.getRtuAddr()); + intake.setIsOpen(isOpen); + } + voGroupIntakes.setIntakes(intakes); + + Map map = new HashMap<>(); + map.put("success", true); + map.put("msg", "鑾峰彇杞亴缁勮鎯呮垚鍔�"); + map.put("content", voGroupIntakes); + return map; + } catch (Exception e) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("msg", "鑾峰彇杞亴缁勮鎯呭け璐�"); + map.put("content", null); + return map; + } + } +} -- Gitblit v1.8.0