diff --git a/tzipc-server/tzipc-admin/src/main/java/com/inspur/web/controller/ipc/IpcDataLogController.java b/tzipc-server/tzipc-admin/src/main/java/com/inspur/web/controller/ipc/IpcDataLogController.java index 465408f..341804a 100644 --- a/tzipc-server/tzipc-admin/src/main/java/com/inspur/web/controller/ipc/IpcDataLogController.java +++ b/tzipc-server/tzipc-admin/src/main/java/com/inspur/web/controller/ipc/IpcDataLogController.java @@ -2,7 +2,10 @@ package com.inspur.web.controller.ipc; import com.inspur.common.core.controller.BaseController; import com.inspur.common.core.domain.AjaxResult; +import com.inspur.common.utils.poi.ExcelUtil; +import com.inspur.ipc.domain.IpcPlcData; import com.inspur.ipc.domain.IpcQueryParams; +import com.inspur.ipc.domain.IpcSensorData; import com.inspur.ipc.service.IIpcDataLogService; import com.inspur.ipc.service.IIpcDataShowService; import org.springframework.beans.factory.annotation.Autowired; @@ -10,6 +13,8 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; /** * 数据展示界面 @@ -21,22 +26,22 @@ import javax.servlet.http.HttpServletResponse; public class IpcDataLogController extends BaseController { @Autowired private IIpcDataLogService iIpcDataLogService; + /** * 查询plc数据记录 */ @PreAuthorize("@ss.hasPermi('ipc:dataLog:query')") @GetMapping(value = "/plc") - public AjaxResult queryPlcDataLog(@RequestBody IpcQueryParams ipcQueryParams) - { + public AjaxResult queryPlcDataLog(IpcQueryParams ipcQueryParams) { return AjaxResult.success(iIpcDataLogService.queryPlcDataLog(ipcQueryParams)); } + /** * 查询传感器温振数据记录 */ @PreAuthorize("@ss.hasPermi('ipc:dataLog:query')") @GetMapping(value = "/sensor") - public AjaxResult querySensorDataLog(@RequestBody IpcQueryParams ipcQueryParams) - { + public AjaxResult querySensorDataLog(IpcQueryParams ipcQueryParams) { return AjaxResult.success(iIpcDataLogService.querySensorDataLog(ipcQueryParams)); } @@ -44,19 +49,26 @@ public class IpcDataLogController extends BaseController { * 导出plc数据记录 */ @PreAuthorize("@ss.hasPermi('ipc:dataLog:query')") - @GetMapping(value = "/plcExport") - public AjaxResult exportPlcDataLog(HttpServletResponse response, @RequestBody IpcQueryParams ipcQueryParams) - { - return AjaxResult.success(iIpcDataLogService.queryPlcDataLog(ipcQueryParams)); + @PostMapping(value = "/plcExport") + public void exportPlcDataLog(HttpServletResponse response, IpcQueryParams ipcQueryParams) { + ipcQueryParams.setPageNum(0); + ipcQueryParams.setPageSize(0); + Map resMap = iIpcDataLogService.queryPlcDataLog(ipcQueryParams); + ExcelUtil util = new ExcelUtil(IpcPlcData.class); + util.exportExcel(response, (List)resMap.get("rows"), "plc温压数据"); } + /** * 导出传感器温振数据记录 */ @PreAuthorize("@ss.hasPermi('ipc:dataLog:query')") - @GetMapping(value = "/sensorExport") - public AjaxResult exportSensorDataLog(HttpServletResponse response,@RequestBody IpcQueryParams ipcQueryParams) - { - return AjaxResult.success(iIpcDataLogService.querySensorDataLog(ipcQueryParams)); + @PostMapping(value = "/sensorExport") + public void exportSensorDataLog(HttpServletResponse response, IpcQueryParams ipcQueryParams) { + ipcQueryParams.setPageNum(0); + ipcQueryParams.setPageSize(0); + Map resMap = iIpcDataLogService.querySensorDataLog(ipcQueryParams); + ExcelUtil util = new ExcelUtil(IpcSensorData.class); + util.exportExcel(response, (List)resMap.get("rows"), "传感器温振数据"); } /** @@ -64,8 +76,7 @@ public class IpcDataLogController extends BaseController { */ @PreAuthorize("@ss.hasPermi('ipc:dataShow:query')") @GetMapping(value = "/getTendencyData") - public AjaxResult getTendencyData(@RequestBody IpcQueryParams ipcQueryParams) - { + public AjaxResult getTendencyData(@RequestBody IpcQueryParams ipcQueryParams) { return AjaxResult.success(iIpcDataLogService.getTendencyData(ipcQueryParams)); } } diff --git a/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java b/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java index bf862eb..33974cb 100644 --- a/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java +++ b/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java @@ -109,7 +109,7 @@ public class IPCPlcDataSyncThread implements Runnable { // fields.put("vz", (float) 0 + Math.random()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); String format = simpleDateFormat.format(new Date()); - tags.put("insertTime", format); + fields.put("insertTime", format); // TODO 根据报警规则校验 // 根据运行状态获取规则 List rulesConfigList = iIpcAlarmRulesConfigService.selectIpcAlarmRulesConfigList(tags.get("part")); diff --git a/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCSensorDataSyncThread.java b/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCSensorDataSyncThread.java index 52b4a5f..859a026 100644 --- a/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCSensorDataSyncThread.java +++ b/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCSensorDataSyncThread.java @@ -57,7 +57,7 @@ public class IPCSensorDataSyncThread implements Runnable { fields.put(field.getFieldValue(), getData()); } } - tags.put("insertTime", format); + fields.put("insertTime", format); InfluxDBService i = SpringUtils.getBean(InfluxDBService.class); i.insert(IpcConstant.SENSOR_MEASUREMENT, tags, fields); } diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcPlcData.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcPlcData.java index 9c97c72..d2fcca5 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcPlcData.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcPlcData.java @@ -4,6 +4,8 @@ import com.inspur.common.annotation.Excel; public class IpcPlcData { + @Excel(name = "时间") + private String insertTime ; @Excel(name = "运行状态") private String rstatus ; @Excel(name = "字段排序") @@ -28,7 +30,8 @@ public class IpcPlcData { public IpcPlcData() { } - public IpcPlcData(String rstatus,String pz4, String pz6, String pz14, String pz21, String owc, String ov, String rot, String oip, String od) { + public IpcPlcData(String insertTime, String rstatus, String pz4, String pz6, String pz14, String pz21, String owc, String ov, String rot, String oip, String od) { + this.insertTime = insertTime; this.rstatus = rstatus; this.pz4 = pz4; this.pz6 = pz6; @@ -41,6 +44,14 @@ public class IpcPlcData { this.od = od; } + public String getInsertTime() { + return insertTime; + } + + public void setInsertTime(String insertTime) { + this.insertTime = insertTime; + } + public String getRstatus() { return rstatus; } @@ -124,7 +135,8 @@ public class IpcPlcData { @Override public String toString() { return "IpcPlcData{" + - "rstatus='" + rstatus + '\'' + + "insertTime='" + insertTime + '\'' + + ", rstatus='" + rstatus + '\'' + ", pz4='" + pz4 + '\'' + ", pz6='" + pz6 + '\'' + ", pz14='" + pz14 + '\'' + diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcQueryParams.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcQueryParams.java index defafe9..bc1745e 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcQueryParams.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcQueryParams.java @@ -1,6 +1,8 @@ package com.inspur.ipc.domain; -public class IpcQueryParams { +import com.inspur.common.core.domain.BaseEntity; + +public class IpcQueryParams extends BaseEntity { /** * 监测部位 */ diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcSensorData.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcSensorData.java index 8951b51..8542b0a 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcSensorData.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcSensorData.java @@ -3,6 +3,8 @@ package com.inspur.ipc.domain; import com.inspur.common.annotation.Excel; public class IpcSensorData { + @Excel(name = "时间") + private String insertTime ; @Excel(name = "时间") private String stime ; @Excel(name = "轴套区温度") @@ -17,7 +19,8 @@ public class IpcSensorData { public IpcSensorData() { } - public IpcSensorData(String stime, String ssat, String vx, String vy, String vz) { + public IpcSensorData(String insertTime, String stime, String ssat, String vx, String vy, String vz) { + this.insertTime = insertTime; this.stime = stime; this.ssat = ssat; this.vx = vx; @@ -25,6 +28,14 @@ public class IpcSensorData { this.vz = vz; } + public String getInsertTime() { + return insertTime; + } + + public void setInsertTime(String insertTime) { + this.insertTime = insertTime; + } + public String getStime() { return stime; } @@ -68,7 +79,8 @@ public class IpcSensorData { @Override public String toString() { return "IpcSensorData{" + - "stime='" + stime + '\'' + + "insertTime='" + insertTime + '\'' + + ", stime='" + stime + '\'' + ", ssat='" + ssat + '\'' + ", vx='" + vx + '\'' + ", vy='" + vy + '\'' + diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcDataLogServiceImpl.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcDataLogServiceImpl.java index beb59fb..cc39a61 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcDataLogServiceImpl.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcDataLogServiceImpl.java @@ -30,17 +30,13 @@ public class IpcDataLogServiceImpl implements IIpcDataLogService { @Override public Map queryPlcDataLog(IpcQueryParams ipcQueryParams) { Map map = new HashMap<>(); - String tableName = IpcConstant.PLC_MEASUREMENT; - String part = ipcQueryParams.getPart(); - String startTime = InfluxdbTimeUtil.cstToUtc(ipcQueryParams.getStartTime()); - String endTime = InfluxdbTimeUtil.cstToUtc(ipcQueryParams.getEndTime()); // 查询总数 - int total = countInfluxdbList(IpcConstant.PLC_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getIsAlarm(),startTime,endTime); + int total = countInfluxdbList(IpcConstant.PLC_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getIsAlarm(), ipcQueryParams.getStartTime(), ipcQueryParams.getEndTime()); // 查询数据 - List> maps = selectAllDataByPart(IpcConstant.PLC_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getIsAlarm(),startTime,endTime,ipcQueryParams.getPageSize(),ipcQueryParams.getPageNum()); - List list = JSON.parseArray(JSON.toJSONString(maps), IpcPlcData.class); - map.put("total",total); - map.put("rows",list); + List> maps = selectAllDataByPart(IpcConstant.PLC_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getIsAlarm(), ipcQueryParams.getStartTime(), ipcQueryParams.getEndTime(), ipcQueryParams.getPageSize(), ipcQueryParams.getPageNum()); + List list = JSON.parseArray(JSON.toJSONString(maps), IpcPlcData.class); + map.put("total", total); + map.put("rows", list); return map; } @@ -51,12 +47,12 @@ public class IpcDataLogServiceImpl implements IIpcDataLogService { public Map querySensorDataLog(IpcQueryParams ipcQueryParams) { Map map = new HashMap<>(); // 查询总数 - int total = countInfluxdbList(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getIsAlarm(),ipcQueryParams.getStartTime(), ipcQueryParams.getEndTime()); + int total = countInfluxdbList(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getIsAlarm(), ipcQueryParams.getStartTime(), ipcQueryParams.getEndTime()); // 查询数据 - List> maps = selectAllDataByPart(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getIsAlarm(),ipcQueryParams.getStartTime(), ipcQueryParams.getEndTime(),ipcQueryParams.getPageSize(),ipcQueryParams.getPageNum()); - List list = JSON.parseArray(JSON.toJSONString(maps), IpcPlcData.class); - map.put("total",total); - map.put("rows",list); + List> maps = selectAllDataByPart(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getIsAlarm(), ipcQueryParams.getStartTime(), ipcQueryParams.getEndTime(), ipcQueryParams.getPageSize(), ipcQueryParams.getPageNum()); + List list = JSON.parseArray(JSON.toJSONString(maps), IpcSensorData.class); + map.put("total", total); + map.put("rows", list); return map; } @@ -64,8 +60,8 @@ public class IpcDataLogServiceImpl implements IIpcDataLogService { * 趋势数据获取 */ @Override - public Map getTendencyData(IpcQueryParams ipcQueryParams){ - Map map = new HashMap<>(); + public Map getTendencyData(IpcQueryParams ipcQueryParams) { + Map map = new HashMap<>(); String utcStartTime = InfluxdbTimeUtil.cstToUtc(ipcQueryParams.getStartTime()); String utcEndTime = InfluxdbTimeUtil.cstToUtc(ipcQueryParams.getEndTime()); @@ -74,79 +70,88 @@ public class IpcDataLogServiceImpl implements IIpcDataLogService { LocalDateTime etime = LocalDateTime.parse(ipcQueryParams.getEndTime()); long intervalHours = ChronoUnit.HOURS.between(stime, etime); List> list = new ArrayList<>(); - if(intervalHours <= 6){//6小时内全查 - list = selectDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(),ipcQueryParams.getParam(), utcStartTime, utcEndTime); - }else if(intervalHours <= 7*24 ){//7天内,每30s一个 - list = selectLongTimeDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(),ipcQueryParams.getParam(), utcStartTime, utcEndTime, "30s"); - }else if(intervalHours <= 30*24 ){//30天内,每2min一个 - list = selectLongTimeDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(),ipcQueryParams.getParam(), utcStartTime, utcEndTime, "2m"); - }else if (intervalHours <= 90*24){//90天以上,每4h一个 - list = selectLongTimeDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(),ipcQueryParams.getParam(), utcStartTime, utcEndTime, "6m"); + if (intervalHours <= 6) {//6小时内全查 + list = selectDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime); + } else if (intervalHours <= 7 * 24) {//7天内,每30s一个 + list = selectLongTimeDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime, "30s"); + } else if (intervalHours <= 30 * 24) {//30天内,每2min一个 + list = selectLongTimeDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime, "2m"); + } else if (intervalHours <= 90 * 24) {//90天以上,每4h一个 + list = selectLongTimeDataByParamNameandDate(IpcConstant.SENSOR_MEASUREMENT, ipcQueryParams.getPart(), ipcQueryParams.getParam(), utcStartTime, utcEndTime, "6m"); } Map resMap = new HashMap<>(); - if (list.size() == 0){ + if (list.size() == 0) { return null; } - return map; + return map; } /** * 根据字段名称和起止时间查询数据 + * * @param tableName 表名 - * @param part 监测部位 - * @param param 参数 + * @param part 监测部位 + * @param param 参数 * @param startTime 起始时间 - * @param endTime 结束时间 + * @param endTime 结束时间 * @return 数据 */ - private List> selectDataByParamNameandDate(String tableName, String part,String param, String startTime, String endTime){ + private List> selectDataByParamNameandDate(String tableName, String part, String param, String startTime, String endTime) { String sql = "select time," + param + " from " + tableName + " where part = '" + part + "' time >= '" + startTime + "' and time <= '" + endTime + "'"; return influxDBService.queryResultProcess(influxDBService.query(sql)); } /** * 查询长时间数据,每分钟取一条展示(最长3个月) + * * @return */ - private List> selectLongTimeDataByParamNameandDate(String tableName, String part,String param, String startTime, String endTime, String interval){ - String sql = "select time, mean(" + param + ") from " + tableName + " where part = '" + part + "' time >= '" + startTime + "' and time <= '" + endTime + "' group by time(" + interval +")"; + private List> selectLongTimeDataByParamNameandDate(String tableName, String part, String param, String startTime, String endTime, String interval) { + String sql = "select time, mean(" + param + ") from " + tableName + " where part = '" + part + "' time >= '" + startTime + "' and time <= '" + endTime + "' group by time(" + interval + ")"; return influxDBService.queryResultProcess(influxDBService.query(sql)); } /** * 根据监测部位查询最近num条数据 + * * @param tableName 表名 - * @param part 监测部位 + * @param part 监测部位 * @return 数据 */ - private List> selectAllDataByPart(String tableName, String part,String isAlarm,String startTime, String endTime, int pageSize, int pageNum){ - String sql = "select * from " + tableName + " where equ_id = '" + part + "'"; - if(isAlarm != null){ + private List> selectAllDataByPart(String tableName, String part, String isAlarm, String startTime, String endTime, int pageSize, int pageNum) { + String sql = "select * from " + tableName + " where part = '" + part + "'"; + if (isAlarm != null) { sql += " and isAlarm = '" + isAlarm + "'"; } - if(startTime != null){ + if (startTime != null) { + startTime = InfluxdbTimeUtil.cstToUtc(startTime); sql += " and time >= '" + startTime + "'"; } - if(endTime != null){ + if (endTime != null) { + endTime = InfluxdbTimeUtil.cstToUtc(endTime); sql += " and time <= '" + endTime + "'"; } - sql += " order by time desc limit " + pageSize + " offset " +(pageNum - 1)*pageSize; + sql += " order by time desc limit " + pageSize + " offset " + (pageNum - 1) * pageSize; + System.out.println(sql); return influxDBService.queryResultProcess(influxDBService.query(sql)); } - private int countInfluxdbList(String tableName, String part,String isAlarm,String startTime, String endTime){ - String sql = "select count(isAlarm) from " + tableName + " where part = '" + part + "'"; - if(isAlarm != null){ + private int countInfluxdbList(String tableName, String part, String isAlarm, String startTime, String endTime) { + String sql = "select count(insertTime) from " + tableName + " where part = '" + part + "'"; + if (isAlarm != null) { sql += " and isAlarm = '" + isAlarm + "'"; } - if(startTime != null){ + if (startTime != null) { + startTime = InfluxdbTimeUtil.cstToUtc(startTime); sql += " and time >= '" + startTime + "'"; } - if(endTime != null){ + if (endTime != null) { + endTime = InfluxdbTimeUtil.cstToUtc(endTime); sql += " and time <= '" + endTime + "'"; } List> list = influxDBService.queryResultProcess(influxDBService.query(sql)); - return list.size() == 0 ? 0 : ((Double)list.get(0).get("count")).intValue(); + System.out.println(sql); + return list.size() == 0 ? 0 : ((Double) list.get(0).get("count")).intValue(); } } diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcConstant.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcConstant.java index 19c7cd8..115399e 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcConstant.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcConstant.java @@ -39,11 +39,11 @@ public class IpcConstant { /** * plc数据表名 */ - public static final String PLC_MEASUREMENT = "tz_ipc_plc_monitor_data_list"; + public static final String PLC_MEASUREMENT = "tz_ipc_plc_monitor_data_list1"; /** * 温振传感器数据表名 */ - public static final String SENSOR_MEASUREMENT = "tz_ipc_sensor_monitor_data_list"; + public static final String SENSOR_MEASUREMENT = "tz_ipc_sensor_monitor_data_list1"; /** * 操作侧简写 */ diff --git a/tzipc-ui/src/views/ipc/dataLog/plcDataLog.vue b/tzipc-ui/src/views/ipc/dataLog/plcDataLog.vue index 1fffaad..9f6edab 100644 --- a/tzipc-ui/src/views/ipc/dataLog/plcDataLog.vue +++ b/tzipc-ui/src/views/ipc/dataLog/plcDataLog.vue @@ -5,7 +5,6 @@ ref="queryForm" size="small" :inline="true" - v-show="showSearch" label-width="68px" > + + 搜索 + 重置 + 导出 +