haungxing
2 months ago
9 changed files with 224 additions and 30 deletions
@ -0,0 +1,58 @@
|
||||
package com.hnac.hzims.fdp.vo; |
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springblade.core.tool.utils.Func; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/09/23 14:35 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode |
||||
public class FdpFaultMatchVO implements Serializable { |
||||
|
||||
@JSONField(name = "item_id") |
||||
private String itemId; |
||||
|
||||
@JSONField(name = "item_name") |
||||
private String itemName; |
||||
|
||||
@JSONField(name = "ord") |
||||
private String ord; |
||||
|
||||
@JSONField(name = "station_id") |
||||
private String stationId; |
||||
|
||||
@JSONField(name = "station_name") |
||||
private String stationName; |
||||
|
||||
@JSONField(name = "device_name") |
||||
private String deviceName; |
||||
|
||||
@JSONField(name = "fault_name") |
||||
private String faultName; |
||||
|
||||
@JSONField(name = "is_root") |
||||
private Integer isRoot; |
||||
|
||||
private Integer display; |
||||
|
||||
@JSONField(name = "device_fault_name") |
||||
private String deviceFaultName; |
||||
|
||||
public void setItemName() { |
||||
this.itemId = String.format("%s %s", this.deviceName, this.faultName); |
||||
} |
||||
|
||||
public void setDeviceFaultName() { |
||||
if(Func.isNotEmpty(this.ord)) { |
||||
this.deviceFaultName = String.format("%s %s", this.ord, this.faultName); |
||||
} else { |
||||
this.deviceFaultName = String.format("%s %s", this.deviceName, this.faultName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.hnac.hzims.fdp.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import com.hnac.hzims.fdp.service.IFdpFaultMatchService; |
||||
import com.hnac.hzinfo.api.annotation.ApiInterface; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/09/23 19:11 |
||||
*/ |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/fdp/faultMatch") |
||||
@Api(value = "故障匹配数据接口管理",tags = "故障匹配数据接口管理") |
||||
public class FdpFaultMatchController { |
||||
|
||||
private final IFdpFaultMatchService fdpFaultMatchService; |
||||
|
||||
@GetMapping("/getFdpFaultMatchList") |
||||
@ApiOperation("获取故障匹配数据列表") |
||||
@ApiOperationSupport(order = 1) |
||||
@ApiInterface |
||||
public R<List<JSONObject>> getFdpFaultMatchList() { |
||||
return R.data(fdpFaultMatchService.getFdpFaultMatchList()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.hnac.hzims.fdp.service; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hnac.hzims.fdp.vo.FdpFaultMatchVO; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/09/23 16:14 |
||||
*/ |
||||
public interface IFdpFaultMatchService { |
||||
|
||||
List<JSONObject> getFdpFaultMatchList(); |
||||
|
||||
} |
@ -0,0 +1,99 @@
|
||||
package com.hnac.hzims.fdp.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.alibaba.fastjson.TypeReference; |
||||
import com.alibaba.fastjson.serializer.SerializerFeature; |
||||
import com.google.common.collect.Lists; |
||||
import com.hnac.hzims.fdp.service.IFdpFaultMatchService; |
||||
import com.hnac.hzims.fdp.util.HttpRequestUtil; |
||||
import com.hnac.hzims.fdp.vo.FdpFaultMatchVO; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/09/23 16:15 |
||||
*/ |
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class FdpFaultMatchServiceImpl implements IFdpFaultMatchService { |
||||
|
||||
@Value("${url.getStations}") |
||||
public String stationDataPath; |
||||
@Value("${url.getFaultAndMonitor}") |
||||
public String faultDataPath; |
||||
|
||||
@Override |
||||
public List<JSONObject> getFdpFaultMatchList() { |
||||
List<FdpFaultMatchVO> matchVOList = Lists.newArrayList(); |
||||
// 获取站点列表
|
||||
String result = HttpRequestUtil.postCall(null, stationDataPath, "POST"); |
||||
if (StringUtil.isNotBlank(result)) { |
||||
JSONObject resultObject = JSONObject.parseObject(result); |
||||
JSONArray dataArray = Optional.ofNullable(resultObject.getString("data")).map(JSONArray::parseArray).orElse(null); |
||||
if(Func.isNotEmpty(dataArray)) { |
||||
dataArray.forEach(jsonObject -> { |
||||
JSONObject station = JSONObject.parseObject(jsonObject.toString()); |
||||
String stationId = station.getString("ID"); |
||||
String stationName = station.getString("NAME"); |
||||
List<FdpFaultMatchVO> faultMatchVOList = this.getFdpFaultListByStation(stationId,stationName); |
||||
if(Func.isNotEmpty(faultMatchVOList)) { |
||||
matchVOList.addAll(faultMatchVOList); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
// 根据站点获取故障列表
|
||||
return matchVOList.stream().map(vo -> JSON.toJSONString(vo, SerializerFeature.WriteMapNullValue)).map(JSONObject::parseObject).collect(Collectors.toList()); |
||||
} |
||||
|
||||
/** |
||||
* 根据站点获取故障列表 |
||||
* @param stationId 站点ID |
||||
* @param stationName 站点名称 |
||||
* @return List<FdpFaultMatchVO> |
||||
*/ |
||||
private List<FdpFaultMatchVO> getFdpFaultListByStation(String stationId, String stationName) { |
||||
if (StringUtil.isNotBlank(stationId)) { |
||||
HashMap<String, Object> paramMap = new HashMap<>(); |
||||
paramMap.put("stationId", stationId); |
||||
String result = HttpRequestUtil.postCall(paramMap, faultDataPath, "POST"); |
||||
if (StringUtil.isNotBlank(result)) { |
||||
JSONObject resultObject = JSONObject.parseObject(result); |
||||
JSONArray dataArray = Optional.ofNullable(resultObject.getString("data")) |
||||
.map(JSONObject::parseObject) |
||||
.map(data -> data.getString("faults")) |
||||
.map(JSONArray::parseArray).orElse(null); |
||||
if (Func.isNotEmpty(dataArray)) { |
||||
return dataArray.stream().map(jsonObject -> { |
||||
FdpFaultMatchVO matchVO = new FdpFaultMatchVO(); |
||||
JSONObject fault = JSONObject.parseObject(jsonObject.toString()); |
||||
matchVO.setItemId(fault.getString("ID")); |
||||
matchVO.setOrd(fault.getString("ORD")); |
||||
matchVO.setStationId(stationId); |
||||
matchVO.setStationName(stationName); |
||||
matchVO.setFaultName(fault.getString("NAME")); |
||||
matchVO.setDeviceName(fault.getString("DEVICE_NAME")); |
||||
matchVO.setIsRoot(fault.getInteger("IS_ROOT")); |
||||
matchVO.setDisplay(fault.getInteger("DISPLAY")); |
||||
matchVO.setDeviceFaultName(); |
||||
matchVO.setItemName(); |
||||
return matchVO; |
||||
}).collect(Collectors.toList()); |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue