package com.dy.pipIrrRemote.common; 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.QueryResultVo; import com.dy.pipIrrGlobal.daoPr.PrControllerMapper; import com.dy.pipIrrGlobal.daoPr.PrIntakeMapper; import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper; import com.dy.pipIrrGlobal.daoSe.SeVirtualCardMapper; import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory; import com.dy.pipIrrGlobal.voPr.VoOnLineIntake; import com.dy.pipIrrGlobal.voRm.VoUnclosedValve; import com.dy.pipIrrRemote.common.qo.OnLineIntakesQO; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.common.utils.PojoUtils; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author ZhuBaoMin * @date 2024-05-21 17:14 * @LastEditTime 2024-05-21 17:14 * @Description 命令日志服务类 */ @Slf4j @Service @RequiredArgsConstructor public class CommandSv extends ComSupport { private final RmCommandHistoryMapper rmCommandHistoryMapper; private final PrControllerMapper prControllerMapper; private final SeVirtualCardMapper seVirtualCardMapper; private final PrIntakeMapper prIntakeMapper; /** * 根据取水口ID获取阀控器地址 * @param intakeId 取水口ID * @return 阀控器地址 */ public String getRtuAddrByIntakeId(Long intakeId) { return prControllerMapper.getRtuAddrByIntakeId(intakeId); } /** * 添加命令日志 * @param po 命令日志对象 * @return 字符串类型的主键 */ public String insert(RmCommandHistory po) { rmCommandHistoryMapper.insert(po); return (po.getId()).toString(); } /** * 修改命令日志信息 * @param po 命令日志对象 * @return 影响记录数量 */ public Integer update(RmCommandHistory po) { return rmCommandHistoryMapper.updateByPrimaryKeySelective(po); } /** * 获取取水口列表 * @return */ public QueryResultVo> selectOnLineIntakes(OnLineIntakesQO qo) { Command com = new Command() ; com.id = Command.defaultId; com.code = "LCD0001"; com.type = "innerCommand"; JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); if(response != null && response.getString("code").equals("0001")) { JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap"); HashMap onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class); JSONArray jsonArray = new JSONArray(); for (Map.Entry entry : onLineMap.entrySet()) { JSONObject jsonObject = new JSONObject(); jsonObject.put("rtuAddr", entry.getKey()); jsonObject.put("isOnLine", entry.getValue()); jsonArray.add(jsonObject); } qo.setOnLineMap(jsonArray.toJSONString()); Map params = (Map) PojoUtils.generalize(qo) ; Long itemTotal = prIntakeMapper.getOnLineIntakesCount(params); QueryResultVo> rsVo = new QueryResultVo<>() ; rsVo.pageSize = qo.pageSize ; rsVo.pageCurr = qo.pageCurr ; rsVo.calculateAndSet(itemTotal, params); rsVo.obj = prIntakeMapper.getOnLineIntakes(params); return rsVo; } else { QueryResultVo> rsVo = new QueryResultVo<>(); return rsVo; } } /** * 根据操作员获取常用取水口 * @param operator * @return */ public List getUsedIntakes(Long operator) { Command com = new Command() ; com.id = Command.defaultId; com.code = "LCD0001"; com.type = "innerCommand"; JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); if(response != null && response.getString("code").equals("0001")) { JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap"); HashMap onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class); JSONArray jsonArray = new JSONArray(); for (Map.Entry entry : onLineMap.entrySet()) { JSONObject jsonObject = new JSONObject(); jsonObject.put("rtuAddr", entry.getKey()); jsonObject.put("isOnLine", entry.getValue()); jsonArray.add(jsonObject); } return prIntakeMapper.getUsedIntakes(jsonArray.toJSONString(), operator); } else { return new ArrayList<>(); } } /** * 根据操作员ID获取未关阀记录(包含在线情况) * @param operator * @return */ public List getUnclosedValves(Long operator) { Command com = new Command() ; com.id = Command.defaultId; com.code = "LCD0001"; com.type = "innerCommand"; JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); if(response != null && response.getString("code").equals("0001")) { JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap"); HashMap onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class); JSONArray jsonArray = new JSONArray(); for (Map.Entry entry : onLineMap.entrySet()) { JSONObject jsonObject = new JSONObject(); jsonObject.put("rtuAddr", entry.getKey()); jsonObject.put("isOnLine", entry.getValue()); jsonArray.add(jsonObject); } List res = rmCommandHistoryMapper.getUnclosedValves(jsonArray.toJSONString(), operator); if(res != null) { return res; } else { return new ArrayList<>(); } } else { QueryResultVo> rsVo = new QueryResultVo<>(); return new ArrayList<>(); } } }