opt:西门子车辆状态显示报警信息
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package org.nl.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* RestTemplate 配置类
|
||||
*/
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.nl.wms.ext.acs.controller;
|
||||
|
||||
import org.nl.common.base.TableDataInfo;
|
||||
import org.nl.wms.ext.acs.service.AcsAlarmService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
|
||||
/**
|
||||
* ACS 报警信息控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/acs/alarm")
|
||||
public class AcsAlarmController {
|
||||
|
||||
@Autowired
|
||||
private AcsAlarmService acsAlarmService;
|
||||
|
||||
/**
|
||||
* 获取 AGV 状态
|
||||
* @param deviceCode 设备编码
|
||||
* @return AGV 状态信息
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
public Object getAgvStatus() {
|
||||
return acsAlarmService.getAgvStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 AGV 报警信息
|
||||
* @param deviceCode 设备编码
|
||||
* @return AGV 报警信息列表
|
||||
*/
|
||||
@GetMapping("/alarms")
|
||||
public TableDataInfo getAgvAlarms(@RequestParam String deviceCode) {
|
||||
List<Object> alarms = acsAlarmService.getAgvAlarms(deviceCode);
|
||||
TableDataInfo dataInfo = new TableDataInfo();
|
||||
dataInfo.setContent(alarms);
|
||||
dataInfo.setTotalElements(alarms.size());
|
||||
return dataInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最新报警信息
|
||||
* @param limit 限制数量
|
||||
* @return 最新报警信息列表
|
||||
*/
|
||||
@GetMapping("/alarms/latest")
|
||||
public TableDataInfo getLatestAlarms(@RequestParam(defaultValue = "10") int limit) {
|
||||
List<Object> alarms = acsAlarmService.getLatestAlarms(limit);
|
||||
TableDataInfo dataInfo = new TableDataInfo();
|
||||
dataInfo.setContent(alarms);
|
||||
dataInfo.setTotalElements(alarms.size());
|
||||
return dataInfo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.nl.wms.ext.acs.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ACS 报警信息服务
|
||||
*/
|
||||
public interface AcsAlarmService {
|
||||
|
||||
/**
|
||||
* 获取 AGV 状态
|
||||
* @param deviceCode 设备编码
|
||||
* @return AGV 状态信息
|
||||
*/
|
||||
Object getAgvStatus();
|
||||
|
||||
/**
|
||||
* 获取 AGV 报警信息
|
||||
* @param deviceCode 设备编码
|
||||
* @return AGV 报警信息列表
|
||||
*/
|
||||
List<Object> getAgvAlarms(String deviceCode);
|
||||
|
||||
/**
|
||||
* 获取最新报警信息
|
||||
* @param limit 限制数量
|
||||
* @return 最新报警信息列表
|
||||
*/
|
||||
List<Object> getLatestAlarms(int limit);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package org.nl.wms.ext.acs.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.nl.system.service.param.dao.Param;
|
||||
import org.nl.system.service.param.impl.SysParamServiceImpl;
|
||||
import org.nl.wms.ext.acs.service.AcsAlarmService;
|
||||
import org.nl.wms.ext.acs.service.dto.to.wms.AcsResponse;
|
||||
import org.nl.wms.sch.task_manage.GeneralDefinition;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ACS 报警信息服务实现
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AcsAlarmServiceImpl implements AcsAlarmService {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public List<Object> getAgvStatus() {
|
||||
SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class);
|
||||
//判断是否连接ACS系统
|
||||
Param isConnectAcs = sysParamService.findByCode(GeneralDefinition.IS_CONNECT_ACS);
|
||||
if (ObjectUtil.isEmpty(isConnectAcs)) {
|
||||
log.error("参数表中:" + GeneralDefinition.IS_CONNECT_ACS + "不存在");
|
||||
return null;
|
||||
}
|
||||
String isConnect = isConnectAcs.getValue();
|
||||
//ACS地址:127.0.0.1:8010
|
||||
Param acsUrlObj = sysParamService.findByCode(GeneralDefinition.ACS_URL);
|
||||
if (ObjectUtil.isEmpty(acsUrlObj)) {
|
||||
log.error("参数表中:" + GeneralDefinition.ACS_URL + "不存在");
|
||||
return null;
|
||||
}
|
||||
String acsUrl = acsUrlObj.getValue();
|
||||
if (StrUtil.equals(GeneralDefinition.NO, isConnect)) {
|
||||
log.error("未连接ACS!");
|
||||
return null;
|
||||
}
|
||||
String url = acsUrl + "api/agv_alarm/status";
|
||||
try {
|
||||
// 尝试作为 JSON 数组接收
|
||||
ResponseEntity<List> response = restTemplate.exchange(url, HttpMethod.GET, null, List.class);
|
||||
return response.getBody();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
// 尝试作为 JSON 对象接收
|
||||
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.GET, null, Map.class);
|
||||
Map<String, Object> body = response.getBody();
|
||||
return (List<Object>) body.get("data");
|
||||
} catch (Exception ex) {
|
||||
log.error("获取AGV报警信息失败:" + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> getAgvAlarms(String deviceCode) {
|
||||
SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class);
|
||||
//判断是否连接ACS系统
|
||||
Param isConnectAcs = sysParamService.findByCode(GeneralDefinition.IS_CONNECT_ACS);
|
||||
if (ObjectUtil.isEmpty(isConnectAcs)) {
|
||||
log.error("参数表中:" + GeneralDefinition.IS_CONNECT_ACS + "不存在");
|
||||
return null;
|
||||
}
|
||||
String isConnect = isConnectAcs.getValue();
|
||||
//ACS地址:127.0.0.1:8010
|
||||
Param acsUrlObj = sysParamService.findByCode(GeneralDefinition.ACS_URL);
|
||||
if (ObjectUtil.isEmpty(acsUrlObj)) {
|
||||
log.error("参数表中:" + GeneralDefinition.ACS_URL + "不存在");
|
||||
return null;
|
||||
}
|
||||
String acsUrl = acsUrlObj.getValue();
|
||||
if (StrUtil.equals(GeneralDefinition.NO, isConnect)) {
|
||||
log.error("未连接ACS!");
|
||||
return null;
|
||||
}
|
||||
String url = acsUrl + "api/agv_alarm/alarms?deviceCode=" + deviceCode;
|
||||
try {
|
||||
// 尝试作为 JSON 数组接收
|
||||
ResponseEntity<List> response = restTemplate.exchange(url, HttpMethod.GET, null, List.class);
|
||||
return response.getBody();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
// 尝试作为 JSON 对象接收
|
||||
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.GET, null, Map.class);
|
||||
Map<String, Object> body = response.getBody();
|
||||
return (List<Object>) body.get("data");
|
||||
} catch (Exception ex) {
|
||||
log.error("获取AGV报警信息失败:" + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> getLatestAlarms(int limit) {
|
||||
SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class);
|
||||
//判断是否连接ACS系统
|
||||
Param isConnectAcs = sysParamService.findByCode(GeneralDefinition.IS_CONNECT_ACS);
|
||||
if (ObjectUtil.isEmpty(isConnectAcs)) {
|
||||
log.error("参数表中:" + GeneralDefinition.IS_CONNECT_ACS + "不存在");
|
||||
return null;
|
||||
}
|
||||
String isConnect = isConnectAcs.getValue();
|
||||
//ACS地址:127.0.0.1:8010
|
||||
Param acsUrlObj = sysParamService.findByCode(GeneralDefinition.ACS_URL);
|
||||
if (ObjectUtil.isEmpty(acsUrlObj)) {
|
||||
log.error("参数表中:" + GeneralDefinition.ACS_URL + "不存在");
|
||||
return null;
|
||||
}
|
||||
String acsUrl = acsUrlObj.getValue();
|
||||
if (StrUtil.equals(GeneralDefinition.NO, isConnect)) {
|
||||
log.error("未连接ACS!");
|
||||
return null;
|
||||
}
|
||||
String url = acsUrl + "api/agv_alarm/alarms/latest?limit=" + limit;
|
||||
try {
|
||||
// 尝试作为 JSON 数组接收
|
||||
ResponseEntity<List> response = restTemplate.exchange(url, HttpMethod.GET, null, List.class);
|
||||
return response.getBody();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
// 尝试作为 JSON 对象接收
|
||||
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.GET, null, Map.class);
|
||||
Map<String, Object> body = response.getBody();
|
||||
return (List<Object>) body.get("data");
|
||||
} catch (Exception ex) {
|
||||
log.error("获取最新报警信息失败:" + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user