From 4bfabe4f95a849813ea5827218b699a7dd6f7006 Mon Sep 17 00:00:00 2001 From: zhangjunwen Date: Thu, 5 Sep 2024 18:20:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E8=AF=8A=E6=96=AD=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/util/date/DateUtils.java | 2 +- .../admin/query/DataQueryController.java | 29 +- .../admin/query/vo/CurrentDataRespVO.java | 23 + .../module/data/service/DataQueryService.java | 65 +- .../data/service/IDataQueryService.java | 2 +- imt-ui/src/api/data/query.js | 20 + .../views/system/data/monitordata/index.vue | 1163 ++++++++++++++--- 7 files changed, 1071 insertions(+), 233 deletions(-) create mode 100644 imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/controller/admin/query/vo/CurrentDataRespVO.java create mode 100644 imt-ui/src/api/data/query.js diff --git a/imt-server/imt-framework/imt-common/src/main/java/com/inspur/framework/common/util/date/DateUtils.java b/imt-server/imt-framework/imt-common/src/main/java/com/inspur/framework/common/util/date/DateUtils.java index 1de7c19..043c34f 100644 --- a/imt-server/imt-framework/imt-common/src/main/java/com/inspur/framework/common/util/date/DateUtils.java +++ b/imt-server/imt-framework/imt-common/src/main/java/com/inspur/framework/common/util/date/DateUtils.java @@ -150,7 +150,7 @@ public class DateUtils { } public static String tranUTC2LocalDateTime(String utcTimeString) throws ParseException { - SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); utcFormat.setTimeZone(TimeZone.getTimeZone("UTC")); // 设置UTC时区 Date utcDate = utcFormat.parse(utcTimeString); // 解析UTC时间 SimpleDateFormat localFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/controller/admin/query/DataQueryController.java b/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/controller/admin/query/DataQueryController.java index 587e5ba..1156d2f 100644 --- a/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/controller/admin/query/DataQueryController.java +++ b/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/controller/admin/query/DataQueryController.java @@ -1,7 +1,15 @@ package com.inspur.module.data.controller.admin.query; +import com.inspur.framework.apilog.core.annotation.ApiAccessLog; import com.inspur.framework.common.pojo.CommonResult; +import com.inspur.framework.common.pojo.PageParam; +import com.inspur.framework.common.util.object.BeanUtils; +import com.inspur.framework.excel.core.util.ExcelUtils; +import com.inspur.module.data.controller.admin.query.vo.CurrentDataRespVO; import com.inspur.module.data.service.IDataQueryService; +import com.inspur.module.system.controller.admin.alarm.vo.AlarmDataPageReqVO; +import com.inspur.module.system.controller.admin.alarm.vo.AlarmDataRespVO; +import com.inspur.module.system.dal.dataobject.alarm.AlarmDataDO; import io.swagger.v3.oas.annotations.Operation; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; @@ -9,10 +17,15 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; import java.text.ParseException; import java.util.HashMap; +import java.util.List; import java.util.Map; +import static com.inspur.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static com.inspur.framework.common.pojo.CommonResult.success; /** @@ -30,10 +43,10 @@ public class DataQueryController { @GetMapping("/list") @Operation(summary = "获取/查询网关数据列表") @PreAuthorize("@ss.hasPermission('data:query:list')") - public CommonResult> getData(String equipId, String startTime, String endTime, Integer pageSize, Integer pageNum){ + public CommonResult> getData(String equipId,String tableName, String startTime, String endTime, Integer pageSize, Integer pageNum){ Map resMap = new HashMap<>(); try { - resMap = dataQueryService.selectDataListByPages(equipId,startTime,endTime,pageSize,pageNum); + resMap = dataQueryService.selectDataListByPages(equipId,tableName,startTime,endTime,pageSize,pageNum); } catch (ParseException e) { e.printStackTrace(); return CommonResult.error(800,"时间格式错误"); @@ -41,4 +54,16 @@ public class DataQueryController { return success(resMap); } + @GetMapping("/export-current-excel") + @Operation(summary = "导出机床电流传感器参数 Excel") + @PreAuthorize("@ss.hasPermission('data:query:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportCurrentDataExcel(String equipId,String tableName, String startTime, String endTime, + HttpServletResponse response) throws IOException, ParseException { + List list = (List)dataQueryService.selectDataListByPages(equipId,tableName,startTime,endTime,null,null).get("list"); + // 导出 Excel + ExcelUtils.write(response, "机床电流参数报警记录.xls", "电流数据", CurrentDataRespVO.class, + BeanUtils.toBean(list, CurrentDataRespVO.class)); + } + } diff --git a/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/controller/admin/query/vo/CurrentDataRespVO.java b/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/controller/admin/query/vo/CurrentDataRespVO.java new file mode 100644 index 0000000..6bf9d50 --- /dev/null +++ b/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/controller/admin/query/vo/CurrentDataRespVO.java @@ -0,0 +1,23 @@ +package com.inspur.module.data.controller.admin.query.vo; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +/** + * 电流传感器数据返回对象 + * @Author zhangjunwen + * @create 2024/9/5 + */ +@Data +public class CurrentDataRespVO { + + @ExcelProperty("时间") + private String time; + + @ExcelProperty("x轴推屑电流") + private String x_push_temp; + + @ExcelProperty("y轴推屑电流") + private String y_push_temp; + +} 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 bc96156..4c171ad 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 @@ -24,32 +24,53 @@ public class DataQueryService implements IDataQueryService{ private InfluxDBService influxDBService; @Override - public Map selectDataListByPages(String equipId,String startTime,String endTime, Integer pageSize, Integer pageNum) throws ParseException { + public Map selectDataListByPages(String equipId,String tableName,String startTime,String endTime, Integer pageSize, Integer pageNum){ Map resMap = new HashMap<>(); //TODO 分页查找条数,根据设备id、表名、时间范围、页码、每页条数 - List> dataList = queryDataByTime("data", equipId, startTime, endTime, pageNum, pageSize); + List> dataList = queryDataByTime(tableName, null, startTime, endTime, pageNum, pageSize); + dataList.forEach(map -> { + try { + map.put("time", DateUtils.tranUTC2LocalDateTime(map.get("time").toString())); + } catch (ParseException e) { + throw new RuntimeException(e); + } + }); //TODO 时间需要将查询到的UTC时间转为系统时间(北京时间) - DateUtils.tranUTC2LocalDateTime("2024-08-28T08:00:00Z"); +// DateUtils.tranUTC2LocalDateTime("2024-08-28T08:00:00Z"); //TODO 查询数据总条数 - long total = countDataList("data", "value", equipId, startTime, endTime); - resMap.put("data", dataList); + long total = countDataList(tableName, "x_push_temp", null, startTime, endTime); + resMap.put("list", dataList); resMap.put("total", total); return resMap; } 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("\"") - .append(" where equip_id = '").append(equipId).append("'"); + .append("\"").append(tableName).append("\""); + if(equipId != null){ + sql.append(" where equip_id = '").append(equipId).append("'"); + } if(beginTime != null){ - sql.append(" and time >= '").append(beginTime).append("'"); + if(!sql.toString().contains("where")){ + sql.append(" where"); + }else{ + sql.append(" and"); + } + sql.append(" time >= '").append(beginTime).append("'"); } if(endTime != null){ - sql.append(" and time <= '").append(endTime).append("'"); + if(!sql.toString().contains("where")){ + sql.append(" where"); + }else{ + sql.append(" and"); + } + sql.append(" time <= '").append(endTime).append("'"); + } + if(pageNum != null || pageSize != null) { + sql.append(" order by time desc ") + .append(" limit ").append(pageSize) + .append(" offset ").append((pageNum - 1) * pageSize); } - sql.append(" order by time desc ") - .append(" limit ").append(pageSize) - .append(" offset ").append((pageNum - 1) * pageSize); // .append(" tz('Asia/Shanghai')"); return influxDBService.queryResultProcess(influxDBService.query(sql.toString())); @@ -57,13 +78,25 @@ public class DataQueryService implements IDataQueryService{ 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("\"") - .append(" where equip_id = '").append(equipId).append("'"); + .append("\"").append(tableName).append("\""); + if(equipId != null){ + sql.append(" where equip_id = '").append(equipId).append("'"); + } if(beginTime != null){ - sql.append(" and time >= '").append(beginTime).append("'"); + if(!sql.toString().contains("where")){ + sql.append(" where"); + }else{ + sql.append(" and"); + } + sql.append(" time >= '").append(beginTime).append("'"); } if(endTime != null){ - sql.append(" and time <= '").append(endTime).append("'"); + if(!sql.toString().contains("where")){ + sql.append(" where"); + }else{ + sql.append(" and"); + } + sql.append(" time <= '").append(endTime).append("'"); } return influxDBService.countResultProcess(influxDBService.query(sql.toString())); } diff --git a/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/service/IDataQueryService.java b/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/service/IDataQueryService.java index 7b2194f..8aa1da3 100644 --- a/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/service/IDataQueryService.java +++ b/imt-server/imt-module-data/imt-module-data-biz/src/main/java/com/inspur/module/data/service/IDataQueryService.java @@ -15,6 +15,6 @@ public interface IDataQueryService { * @param pageSize 每页大小 * @param pageNum 当前页码 */ - Map selectDataListByPages(String equipId,String startTime,String endTime,Integer pageSize,Integer pageNum) throws ParseException; + Map selectDataListByPages(String equipId,String tableName,String startTime,String endTime,Integer pageSize,Integer pageNum) throws ParseException; } diff --git a/imt-ui/src/api/data/query.js b/imt-ui/src/api/data/query.js new file mode 100644 index 0000000..d83a8ec --- /dev/null +++ b/imt-ui/src/api/data/query.js @@ -0,0 +1,20 @@ +import request from "@/utils/request"; + +// 根据时间查询超压底缸数据 +export function getDataList(params) { + return request({ + url: "/data/query/list", + method: "get", + params: params, + }); +} + +// 导出机床电流参数报警记录 Excel +export function exportCurrentDataExcel(params) { + return request({ + url: "/data/query/export-current-excel", + method: "get", + params, + responseType: "blob", + }); +} diff --git a/imt-ui/src/views/system/data/monitordata/index.vue b/imt-ui/src/views/system/data/monitordata/index.vue index 4152ab0..13b7c19 100644 --- a/imt-ui/src/views/system/data/monitordata/index.vue +++ b/imt-ui/src/views/system/data/monitordata/index.vue @@ -1,252 +1,989 @@ - - - \ No newline at end of file + +