add 车间看板-五列能源实时数据接口

maser
yinq 2 weeks ago
parent 67dcb4ce66
commit ad5e061b9a

@ -108,5 +108,16 @@ public class EmsBoardController extends BaseController {
return success(result);
}
/**
* -
* @param hashMap
* @return
*/
@GetMapping("/workshopColumns")
public AjaxResult workshopColumns(@RequestParam(required = false) Map hashMap) {
HashMap<String, Object> result = emsBoardService.workshopColumns(hashMap);
return success(result);
}
}

@ -5,6 +5,7 @@ import com.os.ems.report.domain.EnergyStatisticalReport;
import com.os.ems.report.domain.PeaksValleysConsumptionReport;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
/**
@ -29,4 +30,25 @@ public interface EmsReportMapper
* @return
*/
List<PeaksValleysConsumptionReport> peaksValleysConsumptionReportList(Map hashMap);
/**
*
* @param hashMap
* @return
*/
List<Map<String, Object>> selectWorkshopLatestRows(HashMap<String, Object> hashMap);
/**
*
* @param hashMap
* @return
*/
List<Map<String, Object>> selectWorkshopTodayConsumption(HashMap<String, Object> hashMap);
/**
*
* @param hashMap
* @return
*/
List<Map<String, Object>> selectWorkshopTodayPerDevice(HashMap<String, Object> hashMap);
}

@ -65,4 +65,11 @@ public interface IEmsBoardService {
* @return
*/
HashMap<String, Object> realTimeAlarm(Map hashMap);
/**
* -
* @param hashMap
* @return
*/
HashMap<String, Object> workshopColumns(Map hashMap);
}

@ -70,6 +70,9 @@ public class EmsBoardServiceImpl implements IEmsBoardService {
@Autowired
private EmsRecordAlarmDataMapper emsRecordAlarmDataMapper;
@Autowired
private EmsReportMapper emsReportMapper;
/**
*
*
@ -255,5 +258,74 @@ public class EmsBoardServiceImpl implements IEmsBoardService {
return result;
}
@Override
public HashMap<String, Object> workshopColumns(Map hashMap) {
HashMap<String, Object> result = new HashMap<>();
Map<String, String> dateTimeRanges = DateUtils.getDateTimeRanges();
HashMap<String, Object> query = new HashMap<>();
query.put("beginCollectTime", dateTimeRanges.get("todayStart"));
query.put("endCollectTime", dateTimeRanges.get("currentTime"));
List<Map<String, Object>> latestRows = emsReportMapper.selectWorkshopLatestRows(query);
List<Map<String, Object>> consumptionList = emsReportMapper.selectWorkshopTodayConsumption(query);
List<Map<String, Object>> perDeviceList = emsReportMapper.selectWorkshopTodayPerDevice(query);
Map<String, BigDecimal> consumptionMap = new HashMap<>();
for (Map<String, Object> row : consumptionList) {
String type = String.valueOf(row.get("monitorType"));
consumptionMap.put(type, toBigDecimal(row.get("todayConsumption")));
}
Map<String, BigDecimal> perDeviceConsumption = new HashMap<>();
for (Map<String, Object> row : perDeviceList) {
String type = String.valueOf(row.get("monitorType"));
String code = String.valueOf(row.get("monitorCode"));
perDeviceConsumption.put(type + "_" + code, toBigDecimal(row.get("rowTodayConsumption")));
}
LinkedHashMap<String, Map<String, Object>> colMap = new LinkedHashMap<>();
colMap.put(EmsConstants.EMS_ENERGY_TYPE_DNB, createColumn(EmsConstants.EMS_ENERGY_TYPE_DNB, "电", "kWh", consumptionMap));
colMap.put(EmsConstants.EMS_ENERGY_TYPE_WATER, createColumn(EmsConstants.EMS_ENERGY_TYPE_WATER, "水", "m³", consumptionMap));
colMap.put(EmsConstants.EMS_ENERGY_TYPE_STEAM, createColumn(EmsConstants.EMS_ENERGY_TYPE_STEAM, "蒸汽", "t", consumptionMap));
colMap.put(EmsConstants.EMS_ENERGY_TYPE_Air, createColumn(EmsConstants.EMS_ENERGY_TYPE_Air, "压缩空气", "m³", consumptionMap));
colMap.put(EmsConstants.EMS_ENERGY_TYPE_NITROGEN, createColumn(EmsConstants.EMS_ENERGY_TYPE_NITROGEN, "氮气", "m³", consumptionMap));
for (Map<String, Object> row : latestRows) {
String type = String.valueOf(row.get("monitorType"));
Map<String, Object> col = colMap.get(type);
if (col == null) {
continue;
}
String code = String.valueOf(row.get("monitorCode"));
row.put("rowTodayConsumption", perDeviceConsumption.getOrDefault(type + "_" + code, BigDecimal.ZERO));
@SuppressWarnings("unchecked")
List<Map<String, Object>> rows = (List<Map<String, Object>>) col.get("rows");
rows.add(row);
}
result.put("columns", new ArrayList<>(colMap.values()));
return result;
}
private Map<String, Object> createColumn(String monitorType, String name, String unit, Map<String, BigDecimal> consumptionMap) {
Map<String, Object> col = new LinkedHashMap<>();
col.put("monitorType", monitorType);
col.put("name", name);
col.put("todayConsumption", consumptionMap.getOrDefault(monitorType, BigDecimal.ZERO));
col.put("todayUnit", unit);
col.put("rows", new ArrayList<Map<String, Object>>());
return col;
}
private BigDecimal toBigDecimal(Object value) {
if (value == null) {
return BigDecimal.ZERO;
}
if (value instanceof BigDecimal) {
return (BigDecimal) value;
}
return new BigDecimal(String.valueOf(value));
}
}

@ -70,4 +70,229 @@
GROUP BY ebwu.work_unit_code, ebwu.work_unit_name, dnb.pointTime, dnb.priceType
ORDER BY ebwu.work_unit_code, ebwu.work_unit_name, dnb.pointTime, dnb.priceType
</select>
<select id="selectWorkshopLatestRows" resultType="java.util.HashMap" parameterType="java.util.HashMap">
SELECT x.monitorType,
x.monitorCode,
x.monitorName,
x.instantFlow,
x.cumulativeFlow,
x.vA,
x.vB,
x.vC,
x.iA,
x.iB,
x.iC,
x.instantUnit,
x.realtimeUnit
FROM (
SELECT CAST('2' AS VARCHAR(4)) monitorType,
t.monitor_code monitorCode,
bmi.monitor_name monitorName,
NULL instantFlow,
t.zxyg cumulativeFlow,
t.vA vA,
t.vB vB,
t.vC vC,
t.iA iA,
t.iB iB,
t.iC iC,
NULL instantUnit,
'kWh' realtimeUnit
FROM (
SELECT monitor_code,
zxyg,
v_a AS vA,
v_b AS vB,
v_c AS vC,
i_a AS iA,
i_b AS iB,
i_c AS iC,
ROW_NUMBER() OVER (PARTITION BY monitor_code ORDER BY collect_time DESC, obj_id DESC) rn
FROM ems_record_dnb_instant
) t
LEFT JOIN ems_base_monitor_info bmi ON bmi.monitor_code = t.monitor_code
WHERE t.rn = 1
AND bmi.monitor_type = 2
AND bmi.is_ammeter = '1'
UNION ALL
SELECT CAST('3' AS VARCHAR(4)) monitorType,
t.monitor_code monitorCode,
bmi.monitor_name monitorName,
t.flux_flow instantFlow,
t.water_flow cumulativeFlow,
NULL vA,
NULL vB,
NULL vC,
NULL iA,
NULL iB,
NULL iC,
'm³/h' instantUnit,
'm³' realtimeUnit
FROM (
SELECT monitor_code, flux_flow, water_flow,
ROW_NUMBER() OVER (PARTITION BY monitor_code ORDER BY collect_time DESC, obj_id DESC) rn
FROM ems_record_water_instant
) t
LEFT JOIN ems_base_monitor_info bmi ON bmi.monitor_code = t.monitor_code
WHERE t.rn = 1
AND bmi.monitor_type = 3
AND bmi.is_ammeter = '1'
UNION ALL
SELECT CAST('4' AS VARCHAR(4)) monitorType,
t.monitor_code monitorCode,
bmi.monitor_name monitorName,
t.flux_flow instantFlow,
t.steam_flow cumulativeFlow,
NULL vA,
NULL vB,
NULL vC,
NULL iA,
NULL iB,
NULL iC,
't/h' instantUnit,
't' realtimeUnit
FROM (
SELECT monitor_code, flux_flow, steam_flow,
ROW_NUMBER() OVER (PARTITION BY monitor_code ORDER BY collect_time DESC, obj_id DESC) rn
FROM ems_record_steam_instant
) t
LEFT JOIN ems_base_monitor_info bmi ON bmi.monitor_code = t.monitor_code
WHERE t.rn = 1
AND bmi.monitor_type = 4
AND bmi.is_ammeter = '1'
UNION ALL
SELECT CAST('5' AS VARCHAR(4)) monitorType,
t.monitor_code monitorCode,
bmi.monitor_name monitorName,
t.flux_flow instantFlow,
t.steam_flow cumulativeFlow,
NULL vA,
NULL vB,
NULL vC,
NULL iA,
NULL iB,
NULL iC,
'm³/h' instantUnit,
'm³' realtimeUnit
FROM (
SELECT monitor_code, flux_flow, steam_flow,
ROW_NUMBER() OVER (PARTITION BY monitor_code ORDER BY collect_time DESC, obj_id DESC) rn
FROM ems_record_air_instant
) t
LEFT JOIN ems_base_monitor_info bmi ON bmi.monitor_code = t.monitor_code
WHERE t.rn = 1
AND bmi.monitor_type = 5
AND bmi.is_ammeter = '1'
UNION ALL
SELECT CAST('6' AS VARCHAR(4)) monitorType,
t.monitor_code monitorCode,
bmi.monitor_name monitorName,
t.flux_flow instantFlow,
t.steam_flow cumulativeFlow,
NULL vA,
NULL vB,
NULL vC,
NULL iA,
NULL iB,
NULL iC,
'm³/h' instantUnit,
'm³' realtimeUnit
FROM (
SELECT monitor_code, flux_flow, steam_flow,
ROW_NUMBER() OVER (PARTITION BY monitor_code ORDER BY collect_time DESC, obj_id DESC) rn
FROM ems_record_nitrogen_instant
) t
LEFT JOIN ems_base_monitor_info bmi ON bmi.monitor_code = t.monitor_code
WHERE t.rn = 1
AND bmi.monitor_type = 6
AND bmi.is_ammeter = '1'
) x
ORDER BY x.monitorType, x.monitorCode
</select>
<select id="selectWorkshopTodayPerDevice" resultType="java.util.HashMap" parameterType="java.util.HashMap">
SELECT CAST('2' AS VARCHAR(4)) monitorType,
monitor_code monitorCode,
CAST(CASE WHEN MAX(zxyg) - MIN(zxyg) > 0 THEN MAX(zxyg) - MIN(zxyg) ELSE 0 END AS DECIMAL(18, 2)) rowTodayConsumption
FROM ems_record_dnb_instant
WHERE collect_time BETWEEN #{beginCollectTime} AND #{endCollectTime}
GROUP BY monitor_code
UNION ALL
SELECT CAST('3' AS VARCHAR(4)) monitorType,
monitor_code monitorCode,
CAST(CASE WHEN MAX(water_flow) - MIN(water_flow) > 0 THEN MAX(water_flow) - MIN(water_flow) ELSE 0 END AS DECIMAL(18, 2)) rowTodayConsumption
FROM ems_record_water_instant
WHERE collect_time BETWEEN #{beginCollectTime} AND #{endCollectTime}
GROUP BY monitor_code
UNION ALL
SELECT CAST('4' AS VARCHAR(4)) monitorType,
monitor_code monitorCode,
CAST(CASE WHEN MAX(steam_flow) - MIN(steam_flow) > 0 THEN MAX(steam_flow) - MIN(steam_flow) ELSE 0 END AS DECIMAL(18, 2)) rowTodayConsumption
FROM ems_record_steam_instant
WHERE collect_time BETWEEN #{beginCollectTime} AND #{endCollectTime}
GROUP BY monitor_code
UNION ALL
SELECT CAST('5' AS VARCHAR(4)) monitorType,
monitor_code monitorCode,
CAST(CASE WHEN MAX(steam_flow) - MIN(steam_flow) > 0 THEN MAX(steam_flow) - MIN(steam_flow) ELSE 0 END AS DECIMAL(18, 2)) rowTodayConsumption
FROM ems_record_air_instant
WHERE collect_time BETWEEN #{beginCollectTime} AND #{endCollectTime}
GROUP BY monitor_code
UNION ALL
SELECT CAST('6' AS VARCHAR(4)) monitorType,
monitor_code monitorCode,
CAST(CASE WHEN MAX(steam_flow) - MIN(steam_flow) > 0 THEN MAX(steam_flow) - MIN(steam_flow) ELSE 0 END AS DECIMAL(18, 2)) rowTodayConsumption
FROM ems_record_nitrogen_instant
WHERE collect_time BETWEEN #{beginCollectTime} AND #{endCollectTime}
GROUP BY monitor_code
</select>
<select id="selectWorkshopTodayConsumption" resultType="java.util.HashMap" parameterType="java.util.HashMap">
SELECT monitorType, CAST(SUM(val) AS DECIMAL(18, 2)) todayConsumption
FROM (
SELECT CAST('2' AS VARCHAR(4)) monitorType,
CASE WHEN MAX(zxyg) - MIN(zxyg) > 0 THEN MAX(zxyg) - MIN(zxyg) ELSE 0 END val
FROM ems_record_dnb_instant
WHERE collect_time BETWEEN #{beginCollectTime} AND #{endCollectTime}
GROUP BY monitor_code
UNION ALL
SELECT CAST('3' AS VARCHAR(4)) monitorType,
CASE WHEN MAX(water_flow) - MIN(water_flow) > 0 THEN MAX(water_flow) - MIN(water_flow) ELSE 0 END val
FROM ems_record_water_instant
WHERE collect_time BETWEEN #{beginCollectTime} AND #{endCollectTime}
GROUP BY monitor_code
UNION ALL
SELECT CAST('4' AS VARCHAR(4)) monitorType,
CASE WHEN MAX(steam_flow) - MIN(steam_flow) > 0 THEN MAX(steam_flow) - MIN(steam_flow) ELSE 0 END val
FROM ems_record_steam_instant
WHERE collect_time BETWEEN #{beginCollectTime} AND #{endCollectTime}
GROUP BY monitor_code
UNION ALL
SELECT CAST('5' AS VARCHAR(4)) monitorType,
CASE WHEN MAX(steam_flow) - MIN(steam_flow) > 0 THEN MAX(steam_flow) - MIN(steam_flow) ELSE 0 END val
FROM ems_record_air_instant
WHERE collect_time BETWEEN #{beginCollectTime} AND #{endCollectTime}
GROUP BY monitor_code
UNION ALL
SELECT CAST('6' AS VARCHAR(4)) monitorType,
CASE WHEN MAX(steam_flow) - MIN(steam_flow) > 0 THEN MAX(steam_flow) - MIN(steam_flow) ELSE 0 END val
FROM ems_record_nitrogen_instant
WHERE collect_time BETWEEN #{beginCollectTime} AND #{endCollectTime}
GROUP BY monitor_code
) t
GROUP BY monitorType
</select>
</mapper>
Loading…
Cancel
Save