From cacf21776c504f0c444b6aab3c7927bbb0ae6a28 Mon Sep 17 00:00:00 2001 From: zhangjunwen Date: Wed, 9 Oct 2024 18:01:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8E=A5=E6=94=B6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/data/mqtt/MyMqttCallback.java | 4 +- .../module/data/service/DataQueryService.java | 168 +++++++++--------- .../admin/notice/NoticeController.java | 2 + .../dal/mysql/notify/NotifyMessageMapper.java | 10 +- 4 files changed, 95 insertions(+), 89 deletions(-) diff --git a/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/mqtt/MyMqttCallback.java b/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/mqtt/MyMqttCallback.java index 16db6af..efcb862 100644 --- a/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/mqtt/MyMqttCallback.java +++ b/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/mqtt/MyMqttCallback.java @@ -244,7 +244,7 @@ public class MyMqttCallback implements MqttCallback { fields.put(v,(Double.parseDouble(msg.get(k).toString()) - 400) * 1.25); break; case "temp": - fields.put(v,Double.parseDouble(msg.get(k).toString()) * 0.1); + fields.put(v,Double.parseDouble(msg.get(k).toString()) / 10.0); break; default: fields.put(v,msg.get(k)); @@ -258,7 +258,7 @@ public class MyMqttCallback implements MqttCallback { int alarmNum = alarmRulesApi.alarmRulesFilter(fields, rules); logger.info("本次产生报警{}条",alarmNum); } - influxDBService.insert(measurement,tags, fields); + influxDBService.insert(measurement, tags, fields); logger.info("数据已插入{}表中!",measurement); } diff --git a/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/service/DataQueryService.java b/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/service/DataQueryService.java index db95a7e..d2bd006 100644 --- a/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/service/DataQueryService.java +++ b/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/service/DataQueryService.java @@ -23,16 +23,16 @@ import java.util.stream.Collectors; @Service @Validated @Slf4j -public class DataQueryService implements IDataQueryService{ +public class DataQueryService implements IDataQueryService { @Autowired private InfluxDBService influxDBService; @Override - public Map selectDataListByPages(String equipId,String tableName,String startTime,String endTime, Integer pageSize, Integer pageNum){ + public Map selectDataListByPages(String equipId, String tableName, String startTime, String endTime, Integer pageSize, Integer pageNum) { Map resMap = new HashMap<>(); //TODO 分页查找条数,根据设备id、表名、时间范围、页码、每页条数 - List> dataList = queryDataByTime(tableName, null, startTime, endTime, pageNum, pageSize); + List> dataList = queryDataByTime(tableName, equipId, startTime, endTime, pageNum, pageSize); dataList.forEach(map -> { try { String time = map.get("time").toString(); @@ -41,10 +41,14 @@ public class DataQueryService implements IDataQueryService{ throw new RuntimeException(e); } }); - //TODO 时间需要将查询到的UTC时间转为系统时间(北京时间) + //TODO 时间需要将查询到的UTC时间转为系统时间(北京时间) // DateUtils.tranUTC2LocalDateTime("2024-08-28T08:00:00Z"); //TODO 查询数据总条数 - long total = countDataList(tableName, "x_push_temp", null, startTime, endTime); + long total = 0L; + if (dataList.size() != 0) { + List keys = new ArrayList<>(dataList.get(0).keySet()); + total = countDataList(tableName, keys.get(0), null, startTime, endTime); + } resMap.put("list", dataList); resMap.put("total", total); return resMap; @@ -70,13 +74,13 @@ public class DataQueryService implements IDataQueryService{ // } List> list = selectDataByColumnNameandDateSegmentation(equipId, tableName, columnName, startTime, endTime, intervalHours); Map resMap = new HashMap<>(); - if (list.size() == 0){ + if (list.size() == 0) { return null; } List columnList = new ArrayList<>(); - List timelist = new ArrayList<>(); - if(intervalHours > 6){ + List timelist = new ArrayList<>(); + if (intervalHours > 6) { columnName = "mean"; } for (Map data : list) { @@ -93,49 +97,49 @@ public class DataQueryService implements IDataQueryService{ /** * 根据设备id获取排屑电流数据 */ - public Map getCurrentData(String equipId, String startTime, String endTime){ + public Map getCurrentData(String equipId, String startTime, String endTime) { String tableName = "gateway_current_data"; String columnName = "chip_removal_1,chip_removal_2"; - return getAllData2ChartData(equipId,tableName,columnName, startTime, endTime); + return getAllData2ChartData(equipId, tableName, columnName, startTime, endTime); } /** * 根据设备id获取液压数据 */ - public Map getPressData(String equipId, String startTime, String endTime){ + public Map getPressData(String equipId, String startTime, String endTime) { String tableName = "gateway_hy_data"; String columnName = "hy_1,hy_2,hy_3"; - return getAllData2ChartData(equipId,tableName,columnName, startTime, endTime); + return getAllData2ChartData(equipId, tableName, columnName, startTime, endTime); } /** * 根据设备id获取温度数据 */ - public Map getTempData(String equipId, String startTime, String endTime){ + public Map getTempData(String equipId, String startTime, String endTime) { String tableName = "gateway_temp_data"; String columnName = "cr1_temp,cr2_temp,x0_temp,xp_temp,xn_temp,y0_temp,yp_temp,yn_temp,z0_temp,zp_temp,zn_temp"; - return getAllData2ChartData(equipId,tableName,columnName, startTime, endTime); + return getAllData2ChartData(equipId, tableName, columnName, startTime, endTime); } /** * 根据设备id获取振动数据 */ - public Map getVibrData(String equipId, String startTime, String endTime){ + public Map getVibrData(String equipId, String startTime, String endTime) { String tableName = "gateway_aclr_data"; String columnName = "x_aclr_rms,x_speed_rms,x_dis_rms,y_aclr_rms,y_speed_rms,y_dis_rms,z_aclr_rms,z_speed_rms,z_dis_rms," + "x_aclr_peak,x_speed_peak,x_dis_peak,y_aclr_peak,y_speed_peak,y_dis_peak,z_aclr_peak,z_speed_peak,z_dis_peak"; - return getAllData2ChartData(equipId,tableName,columnName, startTime, endTime); + return getAllData2ChartData(equipId, tableName, columnName, startTime, endTime); } /** * 根据设备id获取工作数据 */ - public Map getWorkData(String equipId, String startTime, String endTime){ + public Map getWorkData(String equipId, String startTime, String endTime) { String tableName = "gateway_fanuc_data"; String columnName = "power_time,process_num,total_process,work_time"; - Map resultMap = getAllData2ChartData(equipId,tableName,columnName, startTime, endTime); - if(resultMap == null){ + Map resultMap = getAllData2ChartData(equipId, tableName, columnName, startTime, endTime); + if (resultMap == null) { return null; } List workTimeList = (List) resultMap.get("work_time"); @@ -145,42 +149,42 @@ public class DataQueryService implements IDataQueryService{ return resultMap; } - public Map getAllData2ChartData(String equipId,String tableName,String columns, String startTime, String endTime){ + public Map getAllData2ChartData(String equipId, String tableName, String columns, String startTime, String endTime) { LocalDateTime stime = DateUtils.tranUTCtoLocalDateTime(startTime); LocalDateTime etime = DateUtils.tranUTCtoLocalDateTime(endTime); long intervalHours = ChronoUnit.HOURS.between(stime, etime); List> list = selectDataByColumnNameandDateSegmentation(equipId, tableName, columns, startTime, endTime, intervalHours); Map resMap = new HashMap<>(); - if (list.size() == 0){ + if (list.size() == 0) { return null; } List columnList = new ArrayList<>(); - List timelist = new ArrayList<>(); + List timelist = new ArrayList<>(); String[] columnName = columns.split(","); - if(intervalHours > 6){ - for(int i=0;i < columnName.length;i++){ + if (intervalHours > 6) { + for (int i = 0; i < columnName.length; i++) { columnName[i] = "mean_" + columnName[i]; } } for (String cn : columnName) { - if(cn.trim().length() == 0){ + if (cn.trim().length() == 0) { continue; } String realCn = cn; - if(cn.startsWith("mean")){ + if (cn.startsWith("mean")) { realCn = cn.replaceFirst("mean_", ""); } - resMap.put(realCn, list.stream().map(map->{ - Double data = (Double)map.get(cn); - if("gateway_temp_data".equals(tableName)){//温度处理 - return data/10.0; - } - if("work_time".equals(columnName) || "power_time".equals(columnName)){//时间转小时 - return data/60.0; - } - return data; + resMap.put(realCn, list.stream().map(map -> { + Double data = (Double) map.get(cn); + if ("gateway_temp_data".equals(tableName)) {//温度处理 + return data / 10.0; + } + if ("work_time".equals(columnName) || "power_time".equals(columnName)) {//时间转小时 + return data / 60.0; + } + return data; }).collect(Collectors.toList())); resMap.put("time", list.stream().map(map -> DateUtils.utcToCst(map.get("time").toString())).collect(Collectors.toList())); } @@ -189,19 +193,18 @@ public class DataQueryService implements IDataQueryService{ } /** - *按照策略分段查询数据列表 + * 按照策略分段查询数据列表 */ - private List> selectDataByColumnNameandDateSegmentation(String equipId, String tableName, String columnName, String startTime, String endTime,long intervalHours) - { + private List> selectDataByColumnNameandDateSegmentation(String equipId, String tableName, String columnName, String startTime, String endTime, long intervalHours) { List> list = new ArrayList<>(); - if(intervalHours <= 6){//6小时内全查 - list = selectDataByColumnNameandDate(null,tableName, columnName, startTime, endTime); - }else if(intervalHours <= 7*24 ){//7天内,每30s一个 - list = selectLongTimeDataByColumnNameandDate(null,tableName, columnName, startTime, endTime, "30s"); - }else if(intervalHours <= 30*24 ){//30天内,每2min一个 - list = selectLongTimeDataByColumnNameandDate(null,tableName, columnName, startTime, endTime, "2m"); - }else if (intervalHours <= 90*24){//90天以上,每6min一个 - list = selectLongTimeDataByColumnNameandDate(null,tableName, columnName, startTime, endTime, "6m"); + if (intervalHours <= 6) {//6小时内全查 + list = selectDataByColumnNameandDate(null, tableName, columnName, startTime, endTime); + } else if (intervalHours <= 7 * 24) {//7天内,每30s一个 + list = selectLongTimeDataByColumnNameandDate(null, tableName, columnName, startTime, endTime, "30s"); + } else if (intervalHours <= 30 * 24) {//30天内,每2min一个 + list = selectLongTimeDataByColumnNameandDate(null, tableName, columnName, startTime, endTime, "2m"); + } else if (intervalHours <= 90 * 24) {//90天以上,每6min一个 + list = selectLongTimeDataByColumnNameandDate(null, tableName, columnName, startTime, endTime, "6m"); } return list; } @@ -209,26 +212,26 @@ public class DataQueryService implements IDataQueryService{ private List> queryDataByTime(String tableName, String equipId, String beginTime, String endTime, Integer pageNum, Integer pageSize) { StringBuilder sql = new StringBuilder("select * from ") .append("\"").append(tableName).append("\""); - if(equipId != null){ + if (equipId != null) { sql.append(" where equip_id = '").append(equipId).append("'"); } - if(beginTime != null){ - if(!sql.toString().contains("where")){ + if (beginTime != null) { + if (!sql.toString().contains("where")) { sql.append(" where"); - }else{ + } else { sql.append(" and"); } sql.append(" time >= '").append(beginTime).append("'"); } - if(endTime != null){ - if(!sql.toString().contains("where")){ + if (endTime != null) { + if (!sql.toString().contains("where")) { sql.append(" where"); - }else{ + } else { sql.append(" and"); } sql.append(" time <= '").append(endTime).append("'"); } - if(pageNum != null || pageSize != null) { + if (pageNum != null || pageSize != null) { sql.append(" order by time desc ") .append(" limit ").append(pageSize) .append(" offset ").append((pageNum - 1) * pageSize); @@ -238,24 +241,24 @@ public class DataQueryService implements IDataQueryService{ return influxDBService.queryResultProcess(influxDBService.query(sql.toString())); } - private long countDataList(String tableName,String field, String equipId, String beginTime, String endTime){ + private long countDataList(String tableName, String field, String equipId, String beginTime, String endTime) { StringBuilder sql = new StringBuilder("select count(").append(field).append(") from ") .append("\"").append(tableName).append("\""); - if(equipId != null){ + if (equipId != null) { sql.append(" where equip_id = '").append(equipId).append("'"); } - if(beginTime != null){ - if(!sql.toString().contains("where")){ + if (beginTime != null) { + if (!sql.toString().contains("where")) { sql.append(" where"); - }else{ + } else { sql.append(" and"); } sql.append(" time >= '").append(beginTime).append("'"); } - if(endTime != null){ - if(!sql.toString().contains("where")){ + if (endTime != null) { + if (!sql.toString().contains("where")) { sql.append(" where"); - }else{ + } else { sql.append(" and"); } sql.append(" time <= '").append(endTime).append("'"); @@ -266,30 +269,31 @@ public class DataQueryService implements IDataQueryService{ /** * 根据字段名称和起止时间查询数据 - * @param tableName 表名 + * + * @param tableName 表名 * @param columnName 字段名称 - * @param beginTime 起始时间 - * @param endTime 结束时间 + * @param beginTime 起始时间 + * @param endTime 结束时间 * @return 数据 */ - private List> selectDataByColumnNameandDate(String equipId, String tableName, String columnName, String beginTime, String endTime){ + private List> selectDataByColumnNameandDate(String equipId, String tableName, String columnName, String beginTime, String endTime) { StringBuilder sql = new StringBuilder("select time,").append(columnName).append(" from ") .append("\"").append(tableName).append("\"");//TODO 修改时间 - if(equipId != null){ + if (equipId != null) { sql.append(" where equip_id = '").append(equipId).append("'"); } - if(beginTime != null){ - if(!sql.toString().contains("where")){ + if (beginTime != null) { + if (!sql.toString().contains("where")) { sql.append(" where"); - }else{ + } else { sql.append(" and"); } sql.append(" time >= '").append(beginTime).append("'"); } - if(endTime != null){ - if(!sql.toString().contains("where")){ + if (endTime != null) { + if (!sql.toString().contains("where")) { sql.append(" where"); - }else{ + } else { sql.append(" and"); } sql.append(" time <= '").append(endTime).append("'"); @@ -300,27 +304,27 @@ public class DataQueryService implements IDataQueryService{ /** * 查询长时间数据,每分钟取一条展示(最长3个月) */ - private List> selectLongTimeDataByColumnNameandDate(String equipId,String tableName, String columnName, String beginTime, String endTime, String interval){ - if(columnName.split(",").length > 1){ + private List> selectLongTimeDataByColumnNameandDate(String equipId, String tableName, String columnName, String beginTime, String endTime, String interval) { + if (columnName.split(",").length > 1) { columnName = "*"; } StringBuilder sql = new StringBuilder("select time, mean(").append(columnName).append(") from ") .append("\"").append(tableName).append("\""); - if(equipId != null){ + if (equipId != null) { sql.append(" where equip_id = '").append(equipId).append("'"); } - if(beginTime != null){ - if(!sql.toString().contains("where")){ + if (beginTime != null) { + if (!sql.toString().contains("where")) { sql.append(" where"); - }else{ + } else { sql.append(" and"); } sql.append(" time >= '").append(beginTime).append("'"); } - if(endTime != null){ - if(!sql.toString().contains("where")){ + if (endTime != null) { + if (!sql.toString().contains("where")) { sql.append(" where"); - }else{ + } else { sql.append(" and"); } sql.append(" time <= '").append(endTime).append("'"); diff --git a/imt-server/imt-module-system/imt-module-system-biz/src/main/java/com/inspur/module/system/controller/admin/notice/NoticeController.java b/imt-server/imt-module-system/imt-module-system-biz/src/main/java/com/inspur/module/system/controller/admin/notice/NoticeController.java index 1bf4158..77e4e34 100644 --- a/imt-server/imt-module-system/imt-module-system-biz/src/main/java/com/inspur/module/system/controller/admin/notice/NoticeController.java +++ b/imt-server/imt-module-system/imt-module-system-biz/src/main/java/com/inspur/module/system/controller/admin/notice/NoticeController.java @@ -104,6 +104,8 @@ public class NoticeController { Assert.notNull(notice, "公告不能为空"); // 直接插入站内信表 notice.setId(null); + notice.setCreateTime(null); + notice.setUpdateTime(null); NotifyMessageDO notifyMessage = BeanUtils.toBean(notice, NotifyMessageDO.class); notifyMessage.setTemplateNickname(SecurityFrameworkUtils.getLoginUserNickname()); notifyMessage.setTemplateType(notice.getType()); diff --git a/imt-server/imt-module-system/imt-module-system-biz/src/main/java/com/inspur/module/system/dal/mysql/notify/NotifyMessageMapper.java b/imt-server/imt-module-system/imt-module-system-biz/src/main/java/com/inspur/module/system/dal/mysql/notify/NotifyMessageMapper.java index fbf6b13..8287b55 100644 --- a/imt-server/imt-module-system/imt-module-system-biz/src/main/java/com/inspur/module/system/dal/mysql/notify/NotifyMessageMapper.java +++ b/imt-server/imt-module-system/imt-module-system-biz/src/main/java/com/inspur/module/system/dal/mysql/notify/NotifyMessageMapper.java @@ -55,17 +55,17 @@ public interface NotifyMessageMapper extends BaseMapperX { default List selectUnreadListByUserIdAndUserType(Long userId, Integer userType, Integer size) { return selectList(new QueryWrapperX() // 由于要使用 limitN 语句,所以只能用 QueryWrapperX - .eq("user_id", userId) - .eq("user_type", userType) +// .eq("user_id", userId) +// .eq("user_type", userType) .eq("read_status", false) .orderByDesc("id").limitN(size)); } default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType) { return selectCount(new LambdaQueryWrapperX() - .eq(NotifyMessageDO::getReadStatus, false) - .eq(NotifyMessageDO::getUserId, userId) - .eq(NotifyMessageDO::getUserType, userType)); + .eq(NotifyMessageDO::getReadStatus, false)); +// .eq(NotifyMessageDO::getUserId, userId) +// .eq(NotifyMessageDO::getUserType, userType)); } }