| | |
| | | package com.ld.igds.protocol.modbus.command; |
| | | |
| | | import com.ld.igds.common.CoreSerService; |
| | | import com.ld.igds.constant.BizType; |
| | | import com.ld.igds.io.RemoteEsService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.constant.ProtocolEnum; |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.io.response.BaseResponse; |
| | | import com.ld.igds.io.response.GasResponse; |
| | | import com.ld.igds.modbus.service.HModbusService; |
| | | import com.ld.igds.models.DeviceModbus; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.protocol.modbus.ModbusUtil2; |
| | | import com.ld.igds.protocol.modbus.ServerUtil; |
| | | import com.ld.igds.protocol.modbus.data.ModbusTcp; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Component; |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 当前协议针对标准Modbus-TCP协议 |
| | |
| | | |
| | | public static final String BEAN_ID = "modbus.remoteEsService"; |
| | | |
| | | @Resource |
| | | private HModbusService modbusService; |
| | | @Resource |
| | | private AnalysisService analysisService; |
| | | @Resource |
| | | private CoreSerService coreSerService; |
| | | |
| | | @Override |
| | | public String getProtocol() { |
| | | return null; |
| | | return ProtocolEnum.TCP_MODBUS.getCode(); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse checkEs(BaseRequest request) { |
| | | return null; |
| | | |
| | | String passCode = request.getDepotId(); |
| | | |
| | | try { |
| | | //获取需要执行的设备配置 |
| | | List<DeviceModbus> list = modbusService.getDataByBizType(BizType.ES.getCode(), request.getSerId()); |
| | | |
| | | if(null == list || list.isEmpty()){ |
| | | return new GasResponse(OrderRespEnum.ORDER_ERROR.getCode(), "未获取到Modbus能耗配置信息"); |
| | | } |
| | | ModbusTcp modbusTcp; |
| | | DeviceSer deviceSer; |
| | | for (DeviceModbus deviceModbus : list) { |
| | | modbusTcp = new ModbusTcp(deviceModbus); |
| | | modbusTcp.setIp(request.getIp()); |
| | | modbusTcp.setPort(request.getPort()); |
| | | |
| | | //若Modbus设备配置分机,则使用所配置分机的IP、端口 |
| | | if(StringUtils.isNotEmpty(deviceModbus.getSerId())){ |
| | | deviceSer = coreSerService.getCacheSer(request.getCompanyId(), deviceModbus.getSerId()); |
| | | modbusTcp.setIp(deviceSer.getIp()); |
| | | modbusTcp.setPort(deviceSer.getPort()); |
| | | } |
| | | |
| | | modbusTcp.setBizCode(passCode); |
| | | modbusTcp.setSerId(request.getSerId()); |
| | | modbusTcp.setCompanyId(request.getCompanyId()); |
| | | |
| | | modbusTcp.setAddrExe(ServerUtil.getAddrExe(deviceModbus.getOpen())); |
| | | |
| | | log.debug("--------启动能耗查询---{}-{}", modbusTcp.getSerId(), modbusTcp.getBizCode()); |
| | | Number check = ModbusUtil2.readHoldingRegister(modbusTcp.getIp(), modbusTcp.getPort(), modbusTcp.getAddrExe()); |
| | | |
| | | //解析能耗数据 |
| | | analysisService.analysisEs(request, check); |
| | | } |
| | | } catch (Exception e) { |
| | | return new GasResponse(OrderRespEnum.ORDER_ERROR.getCode(), "后台执行异常:" + e.getLocalizedMessage()); |
| | | } |
| | | |
| | | return new GasResponse(OrderRespEnum.ORDER_SUCCESS); |
| | | } |
| | | } |