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 3a041a4..465408f 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,14 +2,14 @@ package com.inspur.web.controller.ipc; import com.inspur.common.core.controller.BaseController; import com.inspur.common.core.domain.AjaxResult; +import com.inspur.ipc.domain.IpcQueryParams; import com.inspur.ipc.service.IIpcDataLogService; import com.inspur.ipc.service.IIpcDataShowService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; /** * 数据展示界面 @@ -25,18 +25,47 @@ public class IpcDataLogController extends BaseController { * 查询plc数据记录 */ @PreAuthorize("@ss.hasPermi('ipc:dataLog:query')") - @GetMapping(value = "/plc/{part}") - public AjaxResult queryPlcDataLog(@PathVariable String part) + @GetMapping(value = "/plc") + public AjaxResult queryPlcDataLog(@RequestBody IpcQueryParams ipcQueryParams) { - return AjaxResult.success(iIpcDataLogService.queryPlcDataLog(part)); + return AjaxResult.success(iIpcDataLogService.queryPlcDataLog(ipcQueryParams)); } /** * 查询传感器温振数据记录 */ @PreAuthorize("@ss.hasPermi('ipc:dataLog:query')") - @GetMapping(value = "/sensor/{part}") - public AjaxResult querySensorDataLog(@PathVariable String part) + @GetMapping(value = "/sensor") + public AjaxResult querySensorDataLog(@RequestBody IpcQueryParams ipcQueryParams) { - return AjaxResult.success(iIpcDataLogService.querySensorDataLog(part)); + return AjaxResult.success(iIpcDataLogService.querySensorDataLog(ipcQueryParams)); + } + + /** + * 导出plc数据记录 + */ + @PreAuthorize("@ss.hasPermi('ipc:dataLog:query')") + @GetMapping(value = "/plcExport") + public AjaxResult exportPlcDataLog(HttpServletResponse response, @RequestBody IpcQueryParams ipcQueryParams) + { + return AjaxResult.success(iIpcDataLogService.queryPlcDataLog(ipcQueryParams)); + } + /** + * 导出传感器温振数据记录 + */ + @PreAuthorize("@ss.hasPermi('ipc:dataLog:query')") + @GetMapping(value = "/sensorExport") + public AjaxResult exportSensorDataLog(HttpServletResponse response,@RequestBody IpcQueryParams ipcQueryParams) + { + return AjaxResult.success(iIpcDataLogService.querySensorDataLog(ipcQueryParams)); + } + + /** + * 获取趋势图数据 + */ + @PreAuthorize("@ss.hasPermi('ipc:dataShow:query')") + @GetMapping(value = "/getTendencyData") + public AjaxResult getTendencyData(@RequestBody IpcQueryParams ipcQueryParams) + { + return AjaxResult.success(iIpcDataLogService.getTendencyData(ipcQueryParams)); } } diff --git a/tzipc-server/tzipc-admin/src/main/java/com/inspur/web/controller/ipc/IpcDataShowController.java b/tzipc-server/tzipc-admin/src/main/java/com/inspur/web/controller/ipc/IpcDataShowController.java index 9e12817..7d9d7c2 100644 --- a/tzipc-server/tzipc-admin/src/main/java/com/inspur/web/controller/ipc/IpcDataShowController.java +++ b/tzipc-server/tzipc-admin/src/main/java/com/inspur/web/controller/ipc/IpcDataShowController.java @@ -2,6 +2,7 @@ package com.inspur.web.controller.ipc; import com.inspur.common.core.controller.BaseController; import com.inspur.common.core.domain.AjaxResult; +import com.inspur.ipc.domain.IpcQueryParams; import com.inspur.ipc.service.IIpcDataShowService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -29,13 +30,5 @@ public class IpcDataShowController extends BaseController { return AjaxResult.success(iIpcDataShowService.getShowData(parts)); } - /** - * 获取趋势图数据 - */ - @PreAuthorize("@ss.hasPermi('ipc:dataShow:query')") - @GetMapping(value = "/getTendencyData") - public AjaxResult getTendencyData(@RequestBody Map params) - { - return AjaxResult.success(iIpcDataShowService.getTendencyData(params)); - } + } 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 488b5d6..bf862eb 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 @@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory; import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; public class IPCPlcDataSyncThread implements Runnable { private static final Logger logger = LoggerFactory.getLogger(IPCPlcDataSyncThread.class); @@ -108,10 +109,11 @@ 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()); - fields.put("insertTime", format); + tags.put("insertTime", format); // TODO 根据报警规则校验 // 根据运行状态获取规则 List rulesConfigList = iIpcAlarmRulesConfigService.selectIpcAlarmRulesConfigList(tags.get("part")); + rulesConfigList = rulesConfigList.stream().filter(ipcAlarmRulesConfig -> ipcAlarmRulesConfig.getType().equals(IpcConstant.RULE_TYPE_IN_RUNNING)).collect(Collectors.toList()); alarmRecordList.addAll(ipcUtil.dealRealTimeData(fields, tags, CacheConstants.PLC_MONITOR_PARAMS_KEY,rulesConfigList)); i.insert(IpcConstant.PLC_MEASUREMENT, tags, fields); } 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 a1ec85a..52b4a5f 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 @@ -4,6 +4,7 @@ import com.inspur.common.constant.CacheConstants; import com.inspur.common.utils.spring.SpringUtils; import com.inspur.ipc.domain.IpcAlarmRecord; import com.inspur.ipc.domain.IpcMonitorField; +import com.inspur.ipc.domain.IpcQueryParams; import com.inspur.ipc.service.IIpcAlarmRecordService; import com.inspur.ipc.service.IIpcMonitorFieldService; import com.inspur.ipc.utils.IpcConstant; @@ -17,6 +18,7 @@ import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.stream.Collectors; public class IPCSensorDataSyncThread implements Runnable { private static final Logger logger = LoggerFactory.getLogger(IPCPlcDataSyncThread.class); @@ -41,7 +43,6 @@ public class IPCSensorDataSyncThread implements Runnable { // 温振数据 List partList = iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.MONITOR_PART_KEY); List sensorList = iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.SENSOR_MONITOR_PARAMS_KEY); - List alarmRecordList = new ArrayList<>(); // 字典数据列表集合 for (IpcMonitorField part : partList) { Map tags = new TreeMap(); @@ -50,13 +51,13 @@ public class IPCSensorDataSyncThread implements Runnable { for (IpcMonitorField field : sensorList) { // 可以配置源字段,获取时通过源字段获取数据 // field.getSourceField() - if (field.getFieldValue().equals("sensor_time")) { + if (field.getFieldValue().equals("stime")) { fields.put(field.getFieldValue(), getDate()); } else { fields.put(field.getFieldValue(), getData()); } } - fields.put("insertTime", format); + tags.put("insertTime", format); InfluxDBService i = SpringUtils.getBean(InfluxDBService.class); i.insert(IpcConstant.SENSOR_MEASUREMENT, tags, fields); } @@ -67,19 +68,19 @@ public class IPCSensorDataSyncThread implements Runnable { } private String getData() { - String str = ""; + List list = new ArrayList<>(); for (int i = 0; i < 60; i++) { - str += Math.random(); + list.add(Math.random()+""); } - return str; + return list.stream().map(String::valueOf).collect(Collectors.joining(IpcConstant.DATA_SEPARATOR)); } private String getDate() { - String str = ""; + List list = new ArrayList<>(); for (int i = 0; i < 60; i++) { - str += LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss:SSS")); + list.add(LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss:SSS"))); } - return str; + return list.stream().map(String::valueOf).collect(Collectors.joining(IpcConstant.DATA_SEPARATOR)); } } 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 new file mode 100644 index 0000000..9c97c72 --- /dev/null +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcPlcData.java @@ -0,0 +1,139 @@ +package com.inspur.ipc.domain; + +import com.inspur.common.annotation.Excel; + +public class IpcPlcData { + + @Excel(name = "运行状态") + private String rstatus ; + @Excel(name = "字段排序") + private String pz4 ; + @Excel(name = "颗粒度6μm") + private String pz6 ; + @Excel(name = "颗粒度14μm") + private String pz14 ; + @Excel(name = "颗粒度21μm") + private String pz21 ; + @Excel(name = "油水含量") + private String owc ; + @Excel(name = "油品粘度") + private String ov ; + @Excel(name = "回油温度") + private String rot ; + @Excel(name = "进油压力") + private String oip ; + @Excel(name = "油液密度") + private String od ; + + public IpcPlcData() { + } + + public IpcPlcData(String rstatus,String pz4, String pz6, String pz14, String pz21, String owc, String ov, String rot, String oip, String od) { + this.rstatus = rstatus; + this.pz4 = pz4; + this.pz6 = pz6; + this.pz14 = pz14; + this.pz21 = pz21; + this.owc = owc; + this.ov = ov; + this.rot = rot; + this.oip = oip; + this.od = od; + } + + public String getRstatus() { + return rstatus; + } + + public void setRstatus(String rstatus) { + this.rstatus = rstatus; + } + + public String getPz4() { + return pz4; + } + + public void setPz4(String pz4) { + this.pz4 = pz4; + } + + public String getPz6() { + return pz6; + } + + public void setPz6(String pz6) { + this.pz6 = pz6; + } + + public String getPz14() { + return pz14; + } + + public void setPz14(String pz14) { + this.pz14 = pz14; + } + + public String getPz21() { + return pz21; + } + + public void setPz21(String pz21) { + this.pz21 = pz21; + } + + public String getOwc() { + return owc; + } + + public void setOwc(String owc) { + this.owc = owc; + } + + public String getOv() { + return ov; + } + + public void setOv(String ov) { + this.ov = ov; + } + + public String getRot() { + return rot; + } + + public void setRot(String rot) { + this.rot = rot; + } + + public String getOip() { + return oip; + } + + public void setOip(String oip) { + this.oip = oip; + } + + public String getOd() { + return od; + } + + public void setOd(String od) { + this.od = od; + } + + @Override + public String toString() { + return "IpcPlcData{" + + "rstatus='" + rstatus + '\'' + + ", pz4='" + pz4 + '\'' + + ", pz6='" + pz6 + '\'' + + ", pz14='" + pz14 + '\'' + + ", pz21='" + pz21 + '\'' + + ", owc='" + owc + '\'' + + ", ov='" + ov + '\'' + + ", rot='" + rot + '\'' + + ", oip='" + oip + '\'' + + ", od='" + od + '\'' + + '}'; + } +} 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 new file mode 100644 index 0000000..defafe9 --- /dev/null +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcQueryParams.java @@ -0,0 +1,89 @@ +package com.inspur.ipc.domain; + +public class IpcQueryParams { + /** + * 监测部位 + */ + private String part; + /** + * 参数 + */ + private String param; + /** + * 开始时间 + */ + private String startTime; + /** + * 结束时间 + */ + private String endTime; + /** + * 是否报警 + */ + private String isAlarm; + + /** + * 页数 + */ + private int pageNum; + /** + * 每页数据 + */ + private int pageSize; + + public String getPart() { + return part; + } + + public void setPart(String part) { + this.part = part; + } + + public String getParam() { + return param; + } + + public void setParam(String param) { + this.param = param; + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + public String getIsAlarm() { + return isAlarm; + } + + public void setIsAlarm(String isAlarm) { + this.isAlarm = isAlarm; + } + + public int getPageNum() { + return pageNum; + } + + public void setPageNum(int pageNum) { + this.pageNum = pageNum; + } + + public int getPageSize() { + return pageSize; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } +} 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 new file mode 100644 index 0000000..8951b51 --- /dev/null +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/domain/IpcSensorData.java @@ -0,0 +1,78 @@ +package com.inspur.ipc.domain; + +import com.inspur.common.annotation.Excel; + +public class IpcSensorData { + @Excel(name = "时间") + private String stime ; + @Excel(name = "轴套区温度") + private String ssat ; + @Excel(name = "振动x轴") + private String vx ; + @Excel(name = "振动y轴") + private String vy ; + @Excel(name = "振动z轴") + private String vz ; + + public IpcSensorData() { + } + + public IpcSensorData(String stime, String ssat, String vx, String vy, String vz) { + this.stime = stime; + this.ssat = ssat; + this.vx = vx; + this.vy = vy; + this.vz = vz; + } + + public String getStime() { + return stime; + } + + public void setStime(String stime) { + this.stime = stime; + } + + public String getSsat() { + return ssat; + } + + public void setSsat(String ssat) { + this.ssat = ssat; + } + + public String getVx() { + return vx; + } + + public void setVx(String vx) { + this.vx = vx; + } + + public String getVy() { + return vy; + } + + public void setVy(String vy) { + this.vy = vy; + } + + public String getVz() { + return vz; + } + + public void setVz(String vz) { + this.vz = vz; + } + + @Override + public String toString() { + return "IpcSensorData{" + + "stime='" + stime + '\'' + + ", ssat='" + ssat + '\'' + + ", vx='" + vx + '\'' + + ", vy='" + vy + '\'' + + ", vz='" + vz + '\'' + + '}'; + } +} diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcDataLogService.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcDataLogService.java index 99c1913..3cc446f 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcDataLogService.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcDataLogService.java @@ -1,5 +1,9 @@ package com.inspur.ipc.service; +import com.inspur.ipc.domain.IpcPlcData; +import com.inspur.ipc.domain.IpcQueryParams; +import com.inspur.ipc.domain.IpcSensorData; + import java.util.List; import java.util.Map; @@ -12,10 +16,15 @@ public interface IIpcDataLogService { /** * plc数据记录接口 */ - public List> queryPlcDataLog(String part); + Map queryPlcDataLog(IpcQueryParams ipcQueryParams); /** * 温振传感器数据记录接口 */ - public List> querySensorDataLog(String part); + Map querySensorDataLog(IpcQueryParams ipcQueryParams); + + /** + * 趋势数据获取 + */ + Map getTendencyData(IpcQueryParams ipcQueryParams); } diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcDataShowService.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcDataShowService.java index 97eeffa..59b09a1 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcDataShowService.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcDataShowService.java @@ -1,5 +1,7 @@ package com.inspur.ipc.service; +import com.inspur.ipc.domain.IpcQueryParams; + import java.util.Map; /** @@ -13,8 +15,4 @@ public interface IIpcDataShowService { */ public Map getShowData(String [] parts); - /** - * 趋势数据获取 - */ - public Map getTendencyData(Map params); } 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 643f104..beb59fb 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 @@ -1,12 +1,21 @@ package com.inspur.ipc.service.impl; +import com.alibaba.fastjson2.JSON; +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.utils.InfluxdbTimeUtil; import com.inspur.ipc.utils.IpcConstant; import com.inspur.system.service.influx.InfluxDBService; import org.influxdb.dto.QueryResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,19 +28,125 @@ public class IpcDataLogServiceImpl implements IIpcDataLogService { * plc数据记录接口 */ @Override - public List> queryPlcDataLog(String part) { - QueryResult query = influxDBService.query("select * from "+ IpcConstant.PLC_MEASUREMENT +" where part = '" + part + "' order by time desc limit 20"); - List> maps = influxDBService.queryResultProcess(query); - return maps; + 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); + // 查询数据 + 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); + return map; } /** * 温振传感器数据记录接口 */ @Override - public List> querySensorDataLog(String part) { - QueryResult query = influxDBService.query("select * from "+ IpcConstant.SENSOR_MEASUREMENT +" where part = '" + part + "' order by time desc limit 20"); - List> maps = influxDBService.queryResultProcess(query); - return maps; + public Map querySensorDataLog(IpcQueryParams ipcQueryParams) { + Map map = new HashMap<>(); + // 查询总数 + 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); + return map; + } + + /** + * 趋势数据获取 + */ + @Override + public Map getTendencyData(IpcQueryParams ipcQueryParams){ + Map map = new HashMap<>(); + String utcStartTime = InfluxdbTimeUtil.cstToUtc(ipcQueryParams.getStartTime()); + String utcEndTime = InfluxdbTimeUtil.cstToUtc(ipcQueryParams.getEndTime()); + + //计算utcStartTime与utcEndTime的时间差 + LocalDateTime stime = LocalDateTime.parse(ipcQueryParams.getStartTime()); + 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"); + } + + Map resMap = new HashMap<>(); + if (list.size() == 0){ + return null; + } + return map; + } + + /** + * 根据字段名称和起止时间查询数据 + * @param tableName 表名 + * @param part 监测部位 + * @param param 参数 + * @param startTime 起始时间 + * @param endTime 结束时间 + * @return 数据 + */ + 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 +")"; + return influxDBService.queryResultProcess(influxDBService.query(sql)); + } + + /** + * 根据监测部位查询最近num条数据 + * @param tableName 表名 + * @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){ + sql += " and isAlarm = '" + isAlarm + "'"; + } + if(startTime != null){ + sql += " and time >= '" + startTime + "'"; + } + if(endTime != null){ + sql += " and time <= '" + endTime + "'"; + } + sql += " order by time desc limit " + pageSize + " offset " +(pageNum - 1)*pageSize; + 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){ + sql += " and isAlarm = '" + isAlarm + "'"; + } + if(startTime != null){ + sql += " and time >= '" + startTime + "'"; + } + if(endTime != null){ + sql += " and time <= '" + endTime + "'"; + } + List> list = influxDBService.queryResultProcess(influxDBService.query(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/service/impl/IpcDataShowServiceImpl.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcDataShowServiceImpl.java index e219372..039bcce 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcDataShowServiceImpl.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcDataShowServiceImpl.java @@ -1,5 +1,6 @@ package com.inspur.ipc.service.impl; +import com.inspur.ipc.domain.IpcQueryParams; import com.inspur.ipc.service.IIpcDataShowService; import com.inspur.ipc.utils.IpcConstant; import com.inspur.system.service.influx.InfluxDBService; @@ -147,11 +148,11 @@ public class IpcDataShowServiceImpl implements IIpcDataShowService { //振动z轴 List vz = new ArrayList<>(); Map sensorMap=sensorMaps.get(0); - xSensorData.addAll(sensorMap.get("sensor_time") == null ? new ArrayList<>() : Arrays.asList(String.valueOf(sensorMap.get("sensor_time")).split(IpcConstant.DATA_SEPARATOR))); + xSensorData.addAll(sensorMap.get("stime") == null ? new ArrayList<>() : Arrays.asList(String.valueOf(sensorMap.get("stime")).split(IpcConstant.DATA_SEPARATOR))); ssat.addAll(sensorMap.get("ssat") == null ? new ArrayList<>() : Arrays.asList(String.valueOf(sensorMap.get("ssat")).split(IpcConstant.DATA_SEPARATOR))); vx.addAll(sensorMap.get("vx") == null ? new ArrayList<>() : Arrays.asList(String.valueOf(sensorMap.get("vx")).split(IpcConstant.DATA_SEPARATOR))); vy.addAll(sensorMap.get("vy") == null ? new ArrayList<>() : Arrays.asList(String.valueOf(sensorMap.get("vy")).split(IpcConstant.DATA_SEPARATOR))); - vz.addAll(sensorMap.get("sensor_time") == null ? new ArrayList<>() : Arrays.asList(String.valueOf(sensorMap.get("vz")).split(IpcConstant.DATA_SEPARATOR))); + vz.addAll(sensorMap.get("stime") == null ? new ArrayList<>() : Arrays.asList(String.valueOf(sensorMap.get("vz")).split(IpcConstant.DATA_SEPARATOR))); Map map = new HashMap<>(); if (!xSensorData.isEmpty()) { int sensorIndex = xSensorData.size() - 1; @@ -222,12 +223,4 @@ public class IpcDataShowServiceImpl implements IIpcDataShowService { return dateTime; } - /** - * 趋势数据获取 - */ - @Override - public Map getTendencyData(Map params){ - Map map = new HashMap<>(); - return map; - } } diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/InfluxdbTimeUtil.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/InfluxdbTimeUtil.java new file mode 100644 index 0000000..ce90921 --- /dev/null +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/InfluxdbTimeUtil.java @@ -0,0 +1,40 @@ +package com.inspur.ipc.utils; + + +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +/** + *influxdb时间工具类 + * @Author zhangjunwen + * @create 2024/4/1 + */ +public class InfluxdbTimeUtil { + + /** + * 将utc时间转北京时间 + * @param date utc时间 + * @return 北京时间 + */ + public static LocalDateTime utcToCst(String date) { + DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; + LocalDateTime localDateTime = LocalDateTime.parse(date, formatter); + return localDateTime.plusHours(8); + } + + /** + * 将北京时间转utc时间 + * @param date 北京时间 + * @return utc时间 + * 例如:输入”2020-04-01T08:00:00.000“ + * 返回”2020-04-01T00:00:00.000Z“ + */ + public static String cstToUtc(String date){ + LocalDateTime localDateTime = LocalDateTime.parse(date); + String utcTime = localDateTime.atZone(ZoneId.of("UTC+8")).withZoneSameInstant(ZoneId.of("UTC")).format(DateTimeFormatter.ISO_DATE_TIME); + return utcTime.substring(0, utcTime.indexOf("Z")+1); + } +} 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 1db850f..19c7cd8 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 = "tzipc_plc_monitor_data_list"; + public static final String PLC_MEASUREMENT = "tz_ipc_plc_monitor_data_list"; /** * 温振传感器数据表名 */ - public static final String SENSOR_MEASUREMENT = "tzipc_sensor_monitor_data_list"; + public static final String SENSOR_MEASUREMENT = "tz_ipc_sensor_monitor_data_list"; /** * 操作侧简写 */ @@ -99,4 +99,14 @@ public class IpcConstant { */ public static final String RUNNING_STATUS_RUNNING = "4"; + /** + * 规则类型-试运行 + */ + public static final String RULE_TYPE_TRIAL_RUN = "trial_run"; + + /** + * 规则类型-运行中 + */ + public static final String RULE_TYPE_IN_RUNNING = "in_running"; + } diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcUtil.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcUtil.java index d1687cb..f6cf7ea 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcUtil.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcUtil.java @@ -71,22 +71,21 @@ public class IpcUtil { /** * 批量处理实时数据 */ - public List dealRealTimeData(Map map, Map tags, String type,List rulesConfigList) { + public List dealRealTimeData(Map map, Map tags, String type, List rulesConfigList) { List returnList = new ArrayList<>(); + String isAlarm = "0"; for (IpcAlarmRulesConfig rulesConfig : rulesConfigList) { // 判断是否当前参数类型 if (type.equals(rulesConfig.getType())) { if (judgeAlarm(map.get(rulesConfig.getNameKey()), rulesConfig.getReferenceValue1(), rulesConfig.getReferenceValue2(), rulesConfig.getReferenceCon())) { // 报警数据 - tags.put("isAlarm", "1"); - IpcAlarmRecord ipcAlarmRecord = new IpcAlarmRecord(IdUtils.fastSimpleUUID(),rulesConfig.getPartKey(), rulesConfig.getPart(), rulesConfig.getNameKey(), rulesConfig.getName(), String.valueOf(map.get(rulesConfig.getNameKey())), rulesConfig.getUnit(), rulesConfig.getAlarmLevel(), rulesConfig.getReferenceName(), rulesConfig.getAlarmDetail(),rulesConfig.getId()); + isAlarm = "1"; + IpcAlarmRecord ipcAlarmRecord = new IpcAlarmRecord(IdUtils.fastSimpleUUID(), rulesConfig.getPartKey(), rulesConfig.getPart(), rulesConfig.getNameKey(), rulesConfig.getName(), String.valueOf(map.get(rulesConfig.getNameKey())), rulesConfig.getUnit(), rulesConfig.getAlarmLevel(), rulesConfig.getReferenceName(), rulesConfig.getAlarmDetail(), rulesConfig.getId()); returnList.add(ipcAlarmRecord); - } else { - // 正常数据 - tags.put("isAlarm", "0"); } } } + tags.put("isAlarm", isAlarm); return returnList; } } diff --git a/tzipc-ui/src/views/ipc/dataLog/plcDataLog.vue b/tzipc-ui/src/views/ipc/dataLog/plcDataLog.vue index 956c20e..1fffaad 100644 --- a/tzipc-ui/src/views/ipc/dataLog/plcDataLog.vue +++ b/tzipc-ui/src/views/ipc/dataLog/plcDataLog.vue @@ -1,18 +1,64 @@ @@ -129,6 +193,7 @@ import { getFields } from "@/api/ipc/monitorFields"; export default { name: "plcDataLog", + dicts: ["is_alarm"], data() { return { // 遮罩层 @@ -139,12 +204,66 @@ export default { queryParams: { pageNum: 1, pageSize: 10, + part: null, + isAlarm: null, + datetimerange: [], + startTime: null, + endTime: null, }, // 监测部位 monitorPartList: [], part: "", dataList: [], refresh: false, + pickerOptions: { + shortcuts: [ + { + text: "最近一小时", + onClick(picker) { + const end = new Date(); + const start = new Date(); + start.setTime(start.getTime() - 3600 * 1000); + picker.$emit("pick", [start, end]); + }, + }, + { + text: "最近一天", + onClick(picker) { + const end = new Date(); + const start = new Date(); + start.setTime(start.getTime() - 3600 * 1000 * 24); + picker.$emit("pick", [start, end]); + }, + }, + { + text: "最近一周", + onClick(picker) { + const end = new Date(); + const start = new Date(); + start.setTime(start.getTime() - 3600 * 1000 * 24 * 7); + picker.$emit("pick", [start, end]); + }, + }, + { + text: "最近一个月", + onClick(picker) { + const end = new Date(); + const start = new Date(); + start.setTime(start.getTime() - 3600 * 1000 * 24 * 30); + picker.$emit("pick", [start, end]); + }, + }, + { + text: "最近三个月", + onClick(picker) { + const end = new Date(); + const start = new Date(); + start.setTime(start.getTime() - 3600 * 1000 * 24 * 90); + picker.$emit("pick", [start, end]); + }, + }, + ], + }, }; }, created() { @@ -165,6 +284,14 @@ export default { }, /** 查询列表 */ getList() { + if (this.queryParams.datetimerange && this.queryParams.datetimerange[0]) { + this.queryParams.startTime = this.dateToStr( + this.queryParams.datetimerange[0] + ); + this.queryParams.endTime = this.dateToStr( + this.queryParams.datetimerange[1] + ); + } this.loading = true; getPlcDataLog(this.part).then((response) => { this.dataList = response.data; @@ -191,7 +318,7 @@ export default { };