|
@@ -0,0 +1,186 @@
|
|
|
|
|
+package com.zksy.cockpit.entity;
|
|
|
|
|
+
|
|
|
|
|
+import com.zksy.WaterSupply.WaterPlantInfo.domain.WaterPlantInfo;
|
|
|
|
|
+import com.zksy.WaterSupply.WaterPlantInfo.service.IWaterPlantInfoService;
|
|
|
|
|
+import com.zksy.WaterSupply.WaterPumpStation.domain.WaterPumpStation;
|
|
|
|
|
+import com.zksy.WaterSupply.WaterPumpStation.service.IWaterPumpStationService;
|
|
|
|
|
+import com.zksy.base.domain.EquipmentBase;
|
|
|
|
|
+import com.zksy.base.domain.EquipmentStatus;
|
|
|
|
|
+import com.zksy.base.domain.HazardHiddenAccount;
|
|
|
|
|
+import com.zksy.base.domain.PipeNetworkBase;
|
|
|
|
|
+import com.zksy.base.domain.RiskAssessment;
|
|
|
|
|
+import com.zksy.base.service.EquipmentBaseService;
|
|
|
|
|
+import com.zksy.base.service.EquipmentStatusService;
|
|
|
|
|
+import com.zksy.base.service.HazardHiddenAccountService;
|
|
|
|
|
+import com.zksy.base.service.PipeNetworkBaseService;
|
|
|
|
|
+import com.zksy.base.service.RiskAssessmentService;
|
|
|
|
|
+import com.zksy.cockpit.foundation.CockpitDistrict;
|
|
|
|
|
+import com.zksy.cockpit.foundation.CockpitDistrictPrefix;
|
|
|
|
|
+import com.zksy.cockpit.foundation.CockpitErrorCategory;
|
|
|
|
|
+import com.zksy.cockpit.foundation.CockpitErrorPayload;
|
|
|
|
|
+import com.zksy.cockpit.foundation.CockpitInvalidRequestException;
|
|
|
|
|
+import com.zksy.drainage.domain.EngineeringFacility;
|
|
|
|
|
+import com.zksy.drainage.service.EngineeringFacilityService;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class CockpitEntityDetailService {
|
|
|
|
|
+ private static final ZoneId BUSINESS_ZONE = ZoneId.of("Asia/Shanghai");
|
|
|
|
|
+ private final PipeNetworkBaseService pipes;
|
|
|
|
|
+ private final IWaterPlantInfoService plants;
|
|
|
|
|
+ private final IWaterPumpStationService stations;
|
|
|
|
|
+ private final EquipmentBaseService equipment;
|
|
|
|
|
+ private final EngineeringFacilityService engineeringFacilities;
|
|
|
|
|
+ private final EquipmentStatusService equipmentStatuses;
|
|
|
|
|
+ private final HazardHiddenAccountService hazards;
|
|
|
|
|
+ private final RiskAssessmentService risks;
|
|
|
|
|
+
|
|
|
|
|
+ public CockpitEntityDetailService(PipeNetworkBaseService pipes, IWaterPlantInfoService plants,
|
|
|
|
|
+ IWaterPumpStationService stations, EquipmentBaseService equipment,
|
|
|
|
|
+ EngineeringFacilityService engineeringFacilities, EquipmentStatusService equipmentStatuses, HazardHiddenAccountService hazards, RiskAssessmentService risks) {
|
|
|
|
|
+ this.pipes = pipes; this.plants = plants; this.stations = stations;
|
|
|
|
|
+ this.equipment = equipment; this.engineeringFacilities = engineeringFacilities; this.equipmentStatuses = equipmentStatuses; this.hazards = hazards; this.risks = risks;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public CockpitEntityDetailResponse load(String requestId, String categoryValue, String entityId) {
|
|
|
|
|
+ if (blank(entityId)) throw new CockpitInvalidRequestException("entity id is required");
|
|
|
|
|
+ CockpitEntityCategory category = CockpitEntityCategory.parse(categoryValue);
|
|
|
|
|
+ String id = entityId.trim();
|
|
|
|
|
+ switch (category) {
|
|
|
|
|
+ case PIPE_NETWORK: return pipe(requestId, id);
|
|
|
|
|
+ case WATER_PLANT: return plant(requestId, id);
|
|
|
|
|
+ case PUMP_STATION: return station(requestId, id);
|
|
|
|
|
+ case ENGINEERING_FACILITY: return engineeringFacility(requestId, id);
|
|
|
|
|
+ case EMERGENCY_RESOURCE: return resource(requestId, id);
|
|
|
|
|
+ case HAZARD: return hazard(requestId, id);
|
|
|
|
|
+ case PROTECTION_TARGET: return target(requestId, id);
|
|
|
|
|
+ default: throw new CockpitInvalidRequestException("unsupported entity category");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitEntityDetailResponse pipe(String requestId, String id) {
|
|
|
|
|
+ PipeNetworkBase v = pipes.getById(id);
|
|
|
|
|
+ if (v == null) throw missing();
|
|
|
|
|
+ Map<String,Object> a = map(); put(a,"networkType",v.getNetworkType()); put(a,"networkLevel",v.getNetworkLevel());
|
|
|
|
|
+ put(a,"managementUnit",v.getManagementUnit()); put(a,"lengthMeters",v.getLength()); put(a,"diameterMillimeters",v.getDiameter());
|
|
|
|
|
+ put(a,"material",v.getMaterial()); put(a,"buildDate",v.getBuildDate()); put(a,"remark",v.getRemark());
|
|
|
|
|
+ Integer district = CockpitDistrictPrefix.codeOf(v.getNetworkCode());
|
|
|
|
|
+ return response(requestId,"PIPE_NETWORK",v.getNetworkId(),v.getNetworkCode(),v.getNetworkName(),v.getStatus(),
|
|
|
|
|
+ v.getLocation(),district,new CockpitEntityDetailResponse.Coordinates(v.getStartLongitude(),v.getStartLatitude(),v.getEndLongitude(),v.getEndLatitude()),a,v.getUpdateTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitEntityDetailResponse plant(String requestId, String id) {
|
|
|
|
|
+ WaterPlantInfo v = plants.getById(id); if (v == null) throw missing();
|
|
|
|
|
+ Map<String,Object> a=map(); put(a,"waterSourceType",v.getWaterSourceType()); put(a,"designCapacity",v.getDesignCapacity());
|
|
|
|
|
+ put(a,"currentCapacity",v.getCurrentCapacity()); put(a,"treatmentProcess",v.getTreatmentProcess()); put(a,"commissionDate",v.getCommissionDate());
|
|
|
|
|
+ put(a,"waterQualityStandard",v.getWaterQualityStandard()); put(a,"principal",v.getPrincipal()); put(a,"contactPhone",v.getContactPhone()); put(a,"remark",v.getRemark());
|
|
|
|
|
+ return response(requestId,"WATER_PLANT",String.valueOf(v.getId()),v.getPlantCode(),v.getPlantName(),v.getStatus(),v.getLocation(),null,
|
|
|
|
|
+ new CockpitEntityDetailResponse.Coordinates(v.getLongitude(),v.getLatitude(),null,null),a,v.getUpdateTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitEntityDetailResponse station(String requestId, String id) {
|
|
|
|
|
+ WaterPumpStation v=stations.getById(id); if(v==null) throw missing();
|
|
|
|
|
+ Map<String,Object>a=map(); put(a,"stationType",v.getStationType()); put(a,"pumpCount",v.getPumpCount()); put(a,"designFlow",v.getDesignFlow());
|
|
|
|
|
+ put(a,"designHead",v.getDesignHead()); put(a,"powerCapacity",v.getPowerCapacity()); put(a,"commissionDate",v.getCommissionDate());
|
|
|
|
|
+ put(a,"principal",v.getPrincipal()); put(a,"contactPhone",v.getContactPhone()); put(a,"remark",v.getRemark());
|
|
|
|
|
+ return response(requestId,"PUMP_STATION",String.valueOf(v.getId()),v.getStationCode(),v.getStationName(),v.getStatus(),v.getLocation(),null,
|
|
|
|
|
+ new CockpitEntityDetailResponse.Coordinates(v.getLongitude(),v.getLatitude(),null,null),a,v.getUpdateTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitEntityDetailResponse engineeringFacility(String requestId, String id) {
|
|
|
|
|
+ EngineeringFacility v = engineeringFacilities.getById(id);
|
|
|
|
|
+ if (v == null) throw missing();
|
|
|
|
|
+ Map<String,Object> a = map();
|
|
|
|
|
+ put(a, "facilityType", v.getFacilityType());
|
|
|
|
|
+ put(a, "facilityLevel", v.getFacilityLevel());
|
|
|
|
|
+ put(a, "managementUnit", v.getManagementUnit());
|
|
|
|
|
+ put(a, "buildDate", v.getBuildDate());
|
|
|
|
|
+ put(a, "designFlow", v.getDesignFlow());
|
|
|
|
|
+ put(a, "designHead", v.getDesignHead());
|
|
|
|
|
+ put(a, "storageCapacity", v.getStorageCapacity());
|
|
|
|
|
+ put(a, "equipmentIds", v.getEquipmentId());
|
|
|
|
|
+ put(a, "devices", linkedDevices(v.getEquipmentId()));
|
|
|
|
|
+ put(a, "remark", v.getRemark());
|
|
|
|
|
+ return response(requestId, "ENGINEERING_FACILITY", v.getFacilityId(), v.getFacilityCode(),
|
|
|
|
|
+ v.getFacilityName(), v.getStatus(), v.getLocation(), null,
|
|
|
|
|
+ new CockpitEntityDetailResponse.Coordinates(v.getLongitude(), v.getLatitude(), null, null),
|
|
|
|
|
+ a, v.getUpdateTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private java.util.List<Map<String,Object>> linkedDevices(String value) {
|
|
|
|
|
+ java.util.List<Map<String,Object>> rows = new java.util.ArrayList<>();
|
|
|
|
|
+ if (blank(value)) return rows;
|
|
|
|
|
+ for (String rawId : value.split(",")) {
|
|
|
|
|
+ String equipmentId = rawId == null ? "" : rawId.trim();
|
|
|
|
|
+ if (equipmentId.isEmpty()) continue;
|
|
|
|
|
+ EquipmentBase device = equipment.getById(equipmentId);
|
|
|
|
|
+ if (device == null) continue;
|
|
|
|
|
+ EquipmentStatus status = blank(device.getEquipmentCode())
|
|
|
|
|
+ ? null : equipmentStatuses.getByDeviceCode(device.getEquipmentCode());
|
|
|
|
|
+ Map<String,Object> row = map();
|
|
|
|
|
+ put(row, "id", device.getEquipmentId());
|
|
|
|
|
+ put(row, "code", device.getEquipmentCode());
|
|
|
|
|
+ put(row, "name", device.getEquipmentName());
|
|
|
|
|
+ put(row, "type", device.getEquipmentTypeName());
|
|
|
|
|
+ put(row, "location", device.getEquipmentLocation());
|
|
|
|
|
+ if (status != null) {
|
|
|
|
|
+ put(row, "currentStatus", status.getCurrentStatus());
|
|
|
|
|
+ put(row, "alarmStatus", status.getAlarmStatus());
|
|
|
|
|
+ put(row, "onlineStatus", status.getOnlineStatus());
|
|
|
|
|
+ put(row, "statusUpdatedAt", status.getStatusUpdateTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ rows.add(row);
|
|
|
|
|
+ }
|
|
|
|
|
+ return rows;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitEntityDetailResponse resource(String requestId,String id) {
|
|
|
|
|
+ EquipmentBase v=equipment.getById(id); if(v==null) throw missing();
|
|
|
|
|
+ Map<String,Object>a=map(); put(a,"equipmentTypeId",v.getEquipmentTypeId()); put(a,"model",v.getEquipmentModel()); put(a,"specification",v.getEquipmentSpec());
|
|
|
|
|
+ put(a,"manufacturer",v.getManufacturer()); put(a,"assetValue",v.getAssetValue()); put(a,"useLifeYears",v.getUseLife()); put(a,"installTime",v.getInstallTime());
|
|
|
|
|
+ put(a,"maintainer",v.getMaintainer()); put(a,"maintainerPhone",v.getMaintainerPhone()); put(a,"ownershipUnit",v.getOwnershipUnit()); put(a,"image",v.getEquipmentImage()); put(a,"remark",v.getRemark());
|
|
|
|
|
+ return response(requestId,"EMERGENCY_RESOURCE",v.getEquipmentId(),v.getEquipmentCode(),v.getEquipmentName(),null,v.getEquipmentLocation(),CockpitDistrict.codeOf(v.getDistrict()),
|
|
|
|
|
+ new CockpitEntityDetailResponse.Coordinates(v.getLongitude(),v.getLatitude(),null,null),a,v.getUpdateTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitEntityDetailResponse hazard(String requestId,String id) {
|
|
|
|
|
+ HazardHiddenAccount v=hazards.getById(id); if(v==null) throw missing();
|
|
|
|
|
+ Map<String,Object>a=map(); put(a,"hazardType",v.getHazardType()); put(a,"level",v.getHazardLevel()); put(a,"source",v.getHazardSource()); put(a,"description",v.getHazardDesc());
|
|
|
|
|
+ put(a,"networkId",v.getNetworkId()); put(a,"equipmentId",v.getEquipmentId()); put(a,"workOrderId",v.getWorkOrderId()); put(a,"reportUnit",v.getReportUnit()); put(a,"reportTime",v.getReportTime());
|
|
|
|
|
+ put(a,"rectifyPlan",v.getRectifyPlan()); put(a,"rectifyDeadline",v.getRectifyDeadline()); put(a,"rectifyPerson",v.getRectifyPerson()); put(a,"rectifyFeedback",v.getRectifyFeedback()); put(a,"images",v.getHazardImages()); put(a,"remark",v.getRemark());
|
|
|
|
|
+ Integer district=null; if(!blank(v.getEquipmentId())) { EquipmentBase e=equipment.getById(v.getEquipmentId()); if(e!=null) district=CockpitDistrict.codeOf(e.getDistrict()); }
|
|
|
|
|
+ return response(requestId,"HAZARD",v.getHazardId(),v.getHazardNo(),v.getHazardDesc(),v.getHazardStatus(),null,district,
|
|
|
|
|
+ new CockpitEntityDetailResponse.Coordinates(v.getLongitude(),v.getLatitude(),null,null),a,v.getUpdateTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitEntityDetailResponse target(String requestId,String id) {
|
|
|
|
|
+ RiskAssessment v=risks.getById(id); if(v==null||blank(v.getProtectiveTargets())) throw missing();
|
|
|
|
|
+ Map<String,Object>a=map(); put(a,"networkId",v.getNetworkId()); put(a,"riskLevel",v.getRiskLevel()); put(a,"riskScore",v.getRiskScore()); put(a,"riskColor",v.getRiskColor());
|
|
|
|
|
+ put(a,"assessmentModel",v.getAssessmentModel()); put(a,"assessmentTime",v.getAssessmentTime()); put(a,"riskFactors",v.getRiskFactors()); put(a,"hazardSources",v.getHazardSources()); put(a,"remark",v.getRemark());
|
|
|
|
|
+ return response(requestId,"PROTECTION_TARGET",v.getRiskId(),v.getRiskId(),v.getProtectiveTargets(),v.getRiskLevel(),null,null,null,a,v.getUpdateTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static CockpitEntityDetailResponse response(String requestId,String category,String id,String code,String name,String status,String location,Integer district,CockpitEntityDetailResponse.Coordinates coordinates,Map<String,Object> attributes,LocalDateTime updatedAt) {
|
|
|
|
|
+ return new CockpitEntityDetailResponse(requestId,category,id,code,name,status,location,district,coordinates,attributes,format(updatedAt));
|
|
|
|
|
+ }
|
|
|
|
|
+ public CockpitErrorPayload invalidRequest(String requestId) { return error(CockpitErrorCategory.INVALID_REQUEST,"实体详情查询参数不合法",requestId); }
|
|
|
|
|
+ public CockpitErrorPayload notFound(String requestId) { return error(CockpitErrorCategory.NOT_FOUND,"实体不存在",requestId); }
|
|
|
|
|
+ private static CockpitErrorPayload error(CockpitErrorCategory c,String m,String id) { return new CockpitErrorPayload(c,m,id,format(LocalDateTime.now(BUSINESS_ZONE))); }
|
|
|
|
|
+ private static CockpitEntityNotFoundException missing(){return new CockpitEntityNotFoundException("entity not found");}
|
|
|
|
|
+ private static Map<String,Object> map(){return new LinkedHashMap<>();}
|
|
|
|
|
+ private static void put(Map<String,Object> map,String key,Object value) {
|
|
|
|
|
+ if (value != null) {
|
|
|
|
|
+ map.put(key, value);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ private static String format(LocalDateTime value){return value==null?null:DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value.atZone(BUSINESS_ZONE));}
|
|
|
|
|
+ private static boolean blank(String v){return v==null||v.trim().isEmpty();}
|
|
|
|
|
+}
|