fix:添加app-设备概况接口

ck
HuangHuiKang 1 month ago
parent c2bde1b2b9
commit a1db78fd3d

@ -249,6 +249,12 @@ public class DeviceController {
return success(deviceOperationalStatus);
}
@GetMapping("/getDeviceOverview")
@Operation(summary = "获取设备概况")
public CommonResult<DeviceOverviewRespVO> getDeviceOverview() {
return success(deviceService.getDeviceOverview());
}
// ==================== 子表(设备属性) ====================
@ -351,4 +357,4 @@ public class DeviceController {
return success(true);
}
}
}

@ -136,6 +136,8 @@ public interface DeviceService {
DeviceOperationStatusRespVO getDeviceOperationalStatus();
DeviceOverviewRespVO getDeviceOverview();
List<Map<String, Object>> getMultiDeviceAttributes(Long goviewId);
List<DeviceContactModelDO> getDeviceAttributeList(Long deviceId);

@ -1244,6 +1244,61 @@ public class DeviceServiceImpl implements DeviceService {
return result;
}
@Override
public DeviceOverviewRespVO getDeviceOverview() {
DeviceOverviewRespVO result = new DeviceOverviewRespVO();
Integer totalDevices = deviceMapper.getTotalDeviceCount();
int total = totalDevices == null ? 0 : totalDevices;
result.setTotalDevices(total);
List<Long> deviceIds = deviceMapper.getAllDeviceIds();
if (CollectionUtils.isEmpty(deviceIds)) {
result.setRunningCount(0);
result.setStandbyCount(0);
result.setFaultCount(0);
result.setOfflineCount(0);
result.setUtilizationRate("0.00%");
result.setBootRate("0.00%");
result.setFaultRate("0.00%");
return result;
}
Map<Long, String> deviceStatusMap = tdengineService.getLatestDeviceStatusAlternative(deviceIds);
int runningCount = 0;
int standbyCount = 0;
int faultCount = 0;
int offlineCount = 0;
for (Long deviceId : deviceIds) {
String status = deviceStatusMap.get(deviceId);
if ("1".equals(status)) {
runningCount++;
} else if ("2".equals(status)) {
standbyCount++;
} else if ("3".equals(status)) {
faultCount++;
} else {
offlineCount++;
}
}
result.setRunningCount(runningCount);
result.setStandbyCount(standbyCount);
result.setFaultCount(faultCount);
result.setOfflineCount(offlineCount);
double utilizationRate = total > 0 ? (double) runningCount / total * 100 : 0;
double bootRate = total > 0 ? (double) (runningCount + standbyCount + faultCount) / total * 100 : 0;
double faultRate = total > 0 ? (double) faultCount / total * 100 : 0;
result.setUtilizationRate(String.format("%.2f%%", utilizationRate));
result.setBootRate(String.format("%.2f%%", bootRate));
result.setFaultRate(String.format("%.2f%%", faultRate));
return result;
}
/**
*
@ -1652,4 +1707,4 @@ public class DeviceServiceImpl implements DeviceService {
return deviceMapper.deviceLedgerList();
}
}
}

@ -41,6 +41,7 @@ public class BaogongRecordServiceImpl implements BaogongRecordService {
public Long createBaogongRecord(BaogongRecordSaveReqVO createReqVO) {
// 插入
BaogongRecordDO baogongRecord = BeanUtils.toBean(createReqVO, BaogongRecordDO.class);
baogongRecord.setBaogongTime(LocalDateTime.now());
baogongRecordMapper.insert(baogongRecord);
// 返回
return baogongRecord.getId();

@ -123,6 +123,19 @@
<select id="selectTrendByWeekday"
resultType="cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.BaogongRecordTrendDayRespVO">
SELECT
t.day_name AS day,
IFNULL(SUM(IFNULL(t.num, 0) + IFNULL(t.no_pass_num, 0)), 0) AS baogongNum,
CASE
WHEN IFNULL(SUM(IFNULL(t.num, 0) + IFNULL(t.no_pass_num, 0)), 0) = 0 THEN 0
ELSE ROUND(
IFNULL(SUM(IFNULL(t.num, 0)), 0) /
IFNULL(SUM(IFNULL(t.num, 0) + IFNULL(t.no_pass_num, 0)), 0) * 100, 2
)
END AS passRate
FROM (
SELECT
r.num,
r.no_pass_num,
CASE DAYOFWEEK(r.baogong_time)
WHEN 1 THEN '星期日'
WHEN 2 THEN '星期一'
@ -131,15 +144,8 @@
WHEN 5 THEN '星期四'
WHEN 6 THEN '星期五'
WHEN 7 THEN '星期六'
END AS day,
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) AS baogongNum,
CASE
WHEN IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) = 0 THEN 0
ELSE ROUND(
IFNULL(SUM(IFNULL(r.num, 0)), 0) /
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) * 100, 2
)
END AS passRate
END AS day_name,
DAYOFWEEK(r.baogong_time) AS weekday
FROM mes_baogong_record r
WHERE r.deleted = b'0'
<if test="reqVO.beginBaogongTime != null">
@ -148,8 +154,9 @@
<if test="reqVO.endBaogongTime != null">
AND r.baogong_time &lt;= #{reqVO.endBaogongTime}
</if>
GROUP BY DAYOFWEEK(r.baogong_time)
ORDER BY DAYOFWEEK(r.baogong_time) ASC
) t
GROUP BY t.weekday, t.day_name
ORDER BY t.weekday ASC
</select>
<select id="selectTrendByHour"
@ -172,9 +179,8 @@
<if test="reqVO.endBaogongTime != null">
AND r.baogong_time &lt;= #{reqVO.endBaogongTime}
</if>
GROUP BY DATE_FORMAT(r.baogong_time, '%H')
ORDER BY DATE_FORMAT(r.baogong_time, '%H') ASC
GROUP BY DATE_FORMAT(r.baogong_time, '%H:00')
ORDER BY DATE_FORMAT(r.baogong_time, '%H:00') ASC
</select>
</mapper>

@ -65,7 +65,11 @@
<select id="selectTrendByWeekday"
resultType="cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskTrendItemRespVO">
SELECT
CASE DAYOFWEEK(t.create_time)
t.day_name AS day,
t.count
FROM (
SELECT
CASE DAYOFWEEK(create_time)
WHEN 1 THEN '星期日'
WHEN 2 THEN '星期一'
WHEN 3 THEN '星期二'
@ -73,18 +77,19 @@
WHEN 5 THEN '星期四'
WHEN 6 THEN '星期五'
WHEN 7 THEN '星期六'
END AS day,
COUNT(1) AS count
FROM mes_task t
WHERE t.deleted = b'0'
END AS day_name,
DAYOFWEEK(create_time) AS weekday
FROM mes_task
WHERE deleted = b'0'
<if test="reqVO.beginTime != null">
AND t.create_time &gt;= #{reqVO.beginTime}
AND create_time &gt;= #{reqVO.beginTime}
</if>
<if test="reqVO.endTime != null">
AND t.create_time &lt;= #{reqVO.endTime}
AND create_time &lt;= #{reqVO.endTime}
</if>
GROUP BY DAYOFWEEK(t.create_time)
ORDER BY DAYOFWEEK(t.create_time) ASC
) t
GROUP BY t.weekday, t.day_name
ORDER BY t.weekday ASC
</select>
<select id="selectTrendByHour"
@ -100,7 +105,7 @@
<if test="reqVO.endTime != null">
AND t.create_time &lt;= #{reqVO.endTime}
</if>
GROUP BY DATE_FORMAT(t.create_time, '%H')
ORDER BY DATE_FORMAT(t.create_time, '%H') ASC
GROUP BY DATE_FORMAT(t.create_time, '%H:00')
ORDER BY DATE_FORMAT(t.create_time, '%H:00') ASC
</select>
</mapper>

Loading…
Cancel
Save