zhubaomin
6 天以前 346b480ab7848c742065e9bf989abaf43b515613
获取轮灌组详情
4个文件已修改
2个文件已添加
275 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigateGroupMapper.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoGroupIntakes.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoIntake.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigateGroupMapper.xml 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationCtrl.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationSv.java 150 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigateGroupMapper.java
@@ -87,4 +87,18 @@
     * @return
     */
    List<VoGroupResult> getGroupResult_terminate(@Param("planId") Long planId, @Param("terminateTime") Date terminateTime);
    /**
     * 根据轮灌组ID获取轮灌组详情
     * @param groupId
     * @return
     */
    List<VoGroupIntakes> getGroupIntakes(Long groupId);
    /**
     * 根据轮灌组ID获取轮灌组详情列表
     * @param groupId
     * @return
     */
    List<VoIntake> getGroupIntakesList(Long groupId);
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoGroupIntakes.java
New file
@@ -0,0 +1,34 @@
package com.dy.pipIrrGlobal.voIr;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Data;
import java.util.List;
/**
 * @author ZhuBaoMin
 * @date 2025-04-18 17:07
 * @LastEditTime 2025-04-18 17:07
 * @Description 轮灌组详情视图对象
 */
@Data
@JsonPropertyOrder({"projectName", "groupName", "intakes"})
public class VoGroupIntakes {
    private static final long serialVersionUID = 202504181713001L;
    /**
     * 项目名称
     */
    private String projectName;
    /**
     * 轮灌组名称
     */
    private String groupName;
    /**
     * 轮灌组包含的取水口
     */
    private List<VoIntake> intakes;
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoIntake.java
New file
@@ -0,0 +1,32 @@
package com.dy.pipIrrGlobal.voIr;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Data;
/**
 * @author ZhuBaoMin
 * @date 2025-04-18 17:08
 * @LastEditTime 2025-04-18 17:08
 * @Description 取水口视图对象,用于轮灌组详情展示取水口信息,包括名称和在线情况
 */
@Data
@JsonPropertyOrder({"intakeName", "rtuAddr", "isOnLine"})
public class VoIntake {
    private static final long serialVersionUID = 202504181410001L;
    /**
     * 取水口名称
     */
    private String intakeName;
    /**
     * rtu地址
     */
    private String rtuAddr;
    /**
     * 是否在线
     */
    private Boolean isOnLine;
}
pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigateGroupMapper.xml
@@ -338,4 +338,28 @@
        INNER JOIN ir_plan_schedule ps ON ps.schedule_id = sche.id
    WHERE ps.plan_id = #{planId}
  </select>
  <!--根据轮灌组ID获取轮灌组详情-->
  <select id="getGroupIntakes" resultType="com.dy.pipIrrGlobal.voIr.VoGroupIntakes">
    SELECT
      pro.project_name AS projectName,
      gro.group_code AS groupName,
      NULL AS intakes
    FROM ir_irrigate_group gro
           INNER JOIN ir_project_group pg ON pg.group_id = gro.id
           INNER JOIN ir_project pro ON pro.id = pg.project_id
    WHERE gro.deleted = 0 AND gro.id = #{groupId}
  </select>
  <!--根据轮灌组ID获取轮灌组详情列表-->
  <select id="getGroupIntakesList" resultType="com.dy.pipIrrGlobal.voIr.VoIntake">
    SELECT
      con.rtuAddr,
      inta.name AS intakeName,
      NULL AS isOnLine
    FROM ir_group_intake gi
           INNER JOIN pr_intake inta ON inta.id = gi.intake_id
           INNER JOIN pr_controller con ON con.intakeId = gi.intake_id
    WHERE gi.group_id = #{groupId}
  </select>
</mapper>
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationCtrl.java
@@ -3,6 +3,7 @@
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.voIr.VoGroupIntakes;
import com.dy.pipIrrGlobal.voIr.VoGroupSimple;
import com.dy.pipIrrGlobal.voIr.VoProjectSimple;
import com.dy.pipIrrWechat.irrigation.qo.QoGroup;
@@ -11,6 +12,7 @@
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;
import java.util.List;
@@ -59,4 +61,23 @@
            return BaseResponseUtils.buildException(e.getMessage());
        }
    }
    /**
     * 根据轮灌组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-wechat/src/main/java/com/dy/pipIrrWechat/irrigation/IrrigationSv.java
@@ -1,17 +1,38 @@
package com.dy.pipIrrWechat.irrigation;
import com.dy.common.webUtil.QueryResultVo;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
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.BaseResponseUtils;
import com.dy.pipIrrGlobal.rtuMw.Web2RtuMw;
import com.dy.common.webUtil.BaseResponse;
import com.dy.pipIrrGlobal.daoIr.IrIrrigateGroupMapper;
import com.dy.pipIrrGlobal.daoIr.IrProjectMapper;
import com.dy.pipIrrGlobal.rtuMw.CodeLocal;
import com.dy.pipIrrGlobal.voIr.VoGroupIntakes;
import com.dy.pipIrrGlobal.voIr.VoGroupSimple;
import com.dy.pipIrrGlobal.voIr.VoIntake;
import com.dy.pipIrrGlobal.voIr.VoProjectSimple;
import com.dy.pipIrrWechat.irrigation.qo.QoGroup;
import com.dy.pipIrrWechat.irrigation.qo.QoProject;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
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;
@@ -30,6 +51,27 @@
    @Autowired
    private IrIrrigateGroupMapper irIrrigateGroupMapper;
    @Autowired
    private Environment env;
    @Autowired
    private RestTemplate restTemplate;
    private static final String pro_mw = "mw";
    private static final String pro_url = "url";
    protected static final String ContextComSend = "/rtuMw/com/send";
    protected String comSendUrl;
    /**
     * pro_mw:属性
     * tag从控制器中获取
     * key_mw:url的key
     */
    //private Environment env = null;
    //private String pro_mw = "mw";
    private String key_mw = "comSendUrl";
    /**
     * 根据指定条件获取项目记录(精简)
@@ -58,4 +100,110 @@
        return irIrrigateGroupMapper.getSimpleGroups(params);
    }
    /**
     * 根据轮灌组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) {
                intake.setIsOnLine(getRtuStatus(intake.getRtuAddr()));
            }
            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;
        }
    }
    /**
     * 获取rtu在线情况
     * @param rtuAdd
     * @return
     */
    public Boolean getRtuStatus(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;
        }
    }
    /**
     * 发送命令
     *
     * @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();
    }
}