feat(base): 添加设备状态统计功能并修复Excel导出问题

- 1. statusCode 含义
  statusCode	状态	说明
  0	未开机	当天无三色灯数据
  1	运行	最新记录是"三色灯机器运行"
  2	停机	最新记录是"三色灯机器暂停"
  3	待机	最新记录是"三色灯机器待机"
  2. 三个接口返回数据总结
  接口	返回数据
  /statistics	设备汇总统计:总数、运行/停机/待机/未开机台数、开机率
  /deviceStatus	每台设备的实时状态列表:设备编号、名称、产线、状态文字、状态码
  /deviceStartTime	每台设备的当天开机时间:设备编号、名称、产线、开机时间值
  一句话总结:statistics 返回全局统计数字,deviceStatus 返回每台设备当前是运行/停机/待机/未开机,deviceStartTime 返回每台设备今天的开机时间。
- 修复AndonEventLog中Excel导出的操作类型显示问题
- 添加Anonymous注解支持设备参数访问
- 实现设备状态统计功能,包括开机率、运行台数、停机台数、待机台数、未开机台数
- 添加设备状态列表查询接口,返回设备编号、名称、三色灯状态
- 添加设备开机时间查询接口,返回设备当天最新开机时间
- 实现SQL查询统计设备三色灯状态数据
- 添加异常处理和数据验证机制
- 优化设备状态查询性能,使用CTE和窗口函数进行统计计算
master
zangch@mesnac.com 2 months ago
parent 01d48508f6
commit 5b8259d934

@ -3,6 +3,7 @@ package com.aucma.base.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.aucma.common.annotation.Anonymous;
import com.aucma.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
@ -118,5 +119,32 @@ public class BaseDeviceParamValController extends BaseController {
return success(list);
}
/**
*
*
*/
@PreAuthorize("@ss.hasPermi('baseDeviceParamVal:val:list')" )
@GetMapping("/statistics" )
public AjaxResult statistics() {
return success(baseDeviceParamValService.selectDeviceStatusStatistics());
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('baseDeviceParamVal:val:list')" )
@GetMapping("/deviceStatus" )
public AjaxResult deviceStatus() {
return success(baseDeviceParamValService.selectDeviceStatusList());
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('baseDeviceParamVal:val:list')" )
@GetMapping("/deviceStartTime" )
public AjaxResult deviceStartTime() {
return success(baseDeviceParamValService.selectDeviceStartTimeList());
}
}

@ -1,6 +1,8 @@
package com.aucma.base.mapper;
import java.util.List;
import java.util.Map;
import com.aucma.base.domain.BaseDeviceParamVal;
/**
@ -66,4 +68,25 @@ public interface BaseDeviceParamValMapper
* @return
*/
public int deleteBaseDeviceParamValByRecordIds(Long[] recordIds);
/**
*
*
* @return Map
*/
public Map<String, Object> selectDeviceStatusStatistics();
/**
*
*
* @return
*/
public List<Map<String, Object>> selectDeviceStatusList();
/**
*
*
* @return
*/
public List<Map<String, Object>> selectDeviceStartTimeList();
}

@ -1,6 +1,8 @@
package com.aucma.base.service;
import java.util.List;
import java.util.Map;
import com.aucma.base.domain.BaseDeviceParamVal;
/**
@ -66,4 +68,25 @@ public interface IBaseDeviceParamValService
* @return
*/
public int deleteBaseDeviceParamValByRecordId(Long recordId);
/**
*
*
* @return Map
*/
public Map<String, Object> selectDeviceStatusStatistics();
/**
*
*
* @return
*/
public List<Map<String, Object>> selectDeviceStatusList();
/**
*
*
* @return
*/
public List<Map<String, Object>> selectDeviceStartTimeList();
}

@ -1,7 +1,9 @@
package com.aucma.base.service.impl;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -116,4 +118,79 @@ public class BaseDeviceParamValServiceImpl implements IBaseDeviceParamValService
{
return baseDeviceParamValMapper.deleteBaseDeviceParamValByRecordId(recordId);
}
/**
*
*
* @return Map
*/
@Override
public Map<String, Object> selectDeviceStatusStatistics()
{
try {
Map<String, Object> result = baseDeviceParamValMapper.selectDeviceStatusStatistics();
if (result == null) {
result = new HashMap<>();
result.put("totalCount", 0);
result.put("runningCount", 0);
result.put("stoppedCount", 0);
result.put("standbyCount", 0);
result.put("notStartedCount", 0);
result.put("runningRate", "0%");
return result;
}
// 计算开机率
Object totalObj = result.get("TOTALCOUNT");
Object runningObj = result.get("RUNNINGCOUNT");
int total = totalObj != null ? ((Number) totalObj).intValue() : 0;
int running = runningObj != null ? ((Number) runningObj).intValue() : 0;
String runningRate = total > 0 ? String.format("%.2f%%", (running * 100.0 / total)) : "0%";
result.put("runningRate", runningRate);
return result;
} catch (Exception e) {
log.error("查询设备状态统计失败: {}", e.getMessage());
Map<String, Object> result = new HashMap<>();
result.put("totalCount", 0);
result.put("runningCount", 0);
result.put("stoppedCount", 0);
result.put("standbyCount", 0);
result.put("notStartedCount", 0);
result.put("runningRate", "0%");
return result;
}
}
/**
*
*
* @return
*/
@Override
public List<Map<String, Object>> selectDeviceStatusList()
{
try {
List<Map<String, Object>> list = baseDeviceParamValMapper.selectDeviceStatusList();
return list != null ? list : Collections.emptyList();
} catch (Exception e) {
log.error("查询设备状态列表失败: {}", e.getMessage());
return Collections.emptyList();
}
}
/**
*
*
* @return
*/
@Override
public List<Map<String, Object>> selectDeviceStartTimeList()
{
try {
List<Map<String, Object>> list = baseDeviceParamValMapper.selectDeviceStartTimeList();
return list != null ? list : Collections.emptyList();
} catch (Exception e) {
log.error("查询设备开机时间列表失败: {}", e.getMessage());
return Collections.emptyList();
}
}
}

@ -111,4 +111,97 @@
) WHERE rn = 1
) WHERE row_num &lt;= 200
</select>
<!-- 设备状态统计:基于三色灯参数获取设备运行状态统计 -->
<select id="selectDeviceStatusStatistics" resultType="java.util.Map">
WITH today_latest AS (
SELECT
device_code,
param_name,
ROW_NUMBER() OVER (PARTITION BY device_code ORDER BY NVL(record_time, collect_time) DESC) AS rn
FROM base_device_param_val
WHERE TRUNC(collect_time) = TRUNC(SYSDATE)
AND param_name IN ('机台状态-三色灯机器运行', '机台状态-三色灯机器暂停', '机台状态-三色灯机器待机')
),
device_status AS (
SELECT device_code, param_name FROM today_latest WHERE rn = 1
),
status_sum AS (
SELECT
NVL(SUM(CASE WHEN param_name = '机台状态-三色灯机器运行' THEN 1 ELSE 0 END), 0) AS runningCount,
NVL(SUM(CASE WHEN param_name = '机台状态-三色灯机器暂停' THEN 1 ELSE 0 END), 0) AS stoppedCount,
NVL(SUM(CASE WHEN param_name = '机台状态-三色灯机器待机' THEN 1 ELSE 0 END), 0) AS standbyCount
FROM device_status
),
total_cnt AS (
SELECT COUNT(1) AS totalCount FROM base_deviceledger WHERE is_flag = 1
)
SELECT
t.totalCount,
s.runningCount,
s.stoppedCount,
s.standbyCount,
t.totalCount - s.runningCount - s.stoppedCount - s.standbyCount AS notStartedCount
FROM status_sum s, total_cnt t
</select>
<!-- 获取每个设备的编号、名称、三色灯状态 -->
<select id="selectDeviceStatusList" resultType="java.util.Map">
WITH today_latest AS (
SELECT
device_code,
param_name,
ROW_NUMBER() OVER (PARTITION BY device_code ORDER BY NVL(record_time, collect_time) DESC) AS rn
FROM base_device_param_val
WHERE TRUNC(collect_time) = TRUNC(SYSDATE)
AND param_name IN ('机台状态-三色灯机器运行', '机台状态-三色灯机器暂停', '机台状态-三色灯机器待机')
),
device_status AS (
SELECT device_code, param_name FROM today_latest WHERE rn = 1
)
SELECT
d.device_code AS deviceCode,
d.device_name AS deviceName,
d.product_line_code AS productLineCode,
CASE
WHEN s.param_name = '机台状态-三色灯机器运行' THEN '运行'
WHEN s.param_name = '机台状态-三色灯机器暂停' THEN '停机'
WHEN s.param_name = '机台状态-三色灯机器待机' THEN '待机'
ELSE '未开机'
END AS deviceStatus,
CASE
WHEN s.param_name = '机台状态-三色灯机器运行' THEN 1
WHEN s.param_name = '机台状态-三色灯机器暂停' THEN 2
WHEN s.param_name = '机台状态-三色灯机器待机' THEN 3
ELSE 0
END AS statusCode
FROM base_deviceledger d
LEFT JOIN device_status s ON d.device_code = s.device_code
WHERE d.is_flag = 1
ORDER BY d.product_line_code, d.device_code
</select>
<!-- 获取每个设备的开机时间当天最新值 -->
<select id="selectDeviceStartTimeList" resultType="java.util.Map">
WITH today_latest AS (
SELECT
device_code,
param_value,
collect_time,
ROW_NUMBER() OVER (PARTITION BY device_code ORDER BY NVL(record_time, collect_time) DESC) AS rn
FROM base_device_param_val
WHERE TRUNC(collect_time) = TRUNC(SYSDATE)
AND param_name = '机台状态-开机时间'
)
SELECT
d.device_code AS deviceCode,
d.device_name AS deviceName,
d.product_line_code AS productLineCode,
t.param_value AS startTime,
t.collect_time AS collectTime
FROM base_deviceledger d
LEFT JOIN today_latest t ON d.device_code = t.device_code AND t.rn = 1
WHERE d.is_flag = 1
ORDER BY d.product_line_code, d.device_code
</select>
</mapper>

@ -26,7 +26,7 @@ private static final long serialVersionUID=1L;
private Long eventId;
/** 操作类型(创建/确认/分配/升级/解决/取消/评论) */
@Excel(name = "操作类型", readConverterExp = "=建/确认/分配/升级/解决/取消/评论")
@Excel(name = "操作类型", readConverterExp = "=建/确认/分配/升级/解决/取消/评论")
private String operation;
/** 操作内容 */

Loading…
Cancel
Save