zhubaomin
昨天 cd7fd2ea35de966cfd1c6f3038e593097d7a6dec
轮灌组PC端接口
3个文件已修改
1个文件已删除
3个文件已添加
597 ■■■■ 已修改文件
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/command/CommandSv.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanCtrl.java 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanSv.java 120 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigationSv.java 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/qo/QoIrrigatePlan.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationCtrl.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationSv.java 176 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
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());
        }
    }
}
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);
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigationSv.java
File was deleted
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/qo/QoIrrigatePlan.java
New file
@@ -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;
}
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationCtrl.java
New file
@@ -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;
    /**
     * 根据轮灌组ID获取轮灌组详情
     * @param groupId
     * @return
     */
    @GetMapping(path = "/getGroupDetails")
    public BaseResponse<VoGroupIntakes> getGroupDetails(@RequestParam Long groupId) {
        if(groupId == null) {
            return BaseResponseUtils.buildErrorMsg("轮灌组ID不能为空");
        }
        try {
            return BaseResponseUtils.buildSuccess(irrigationSv.getGroupDetails(groupId).get("content"));
        } catch (Exception e) {
            log.error("获取轮灌组详情异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigation/IrrigationSv.java
New file
@@ -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();
    }
    /**
     * 根据轮灌组ID获取轮灌组详情
     * @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);
            // 补全取水口信息(在线情况)
            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;
        }
    }
}