85d87b7a 张雷

奥体项目实时数据接口开发

1 个父辈 98eca395
package com.skua.modules.business.mapper;
import com.skua.modules.business.entity.WhatStructData;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -10,4 +11,6 @@ import java.util.List;
public interface WhatStructDataMapper {
List<WhatStructData> getList();
WhatStructData getOneById(@Param("id") String id);
}
......
......@@ -6,4 +6,8 @@
select * from what_struct_data
</select>
<select id="getOneById" resultType="com.skua.modules.business.entity.WhatStructData">
select * from what_struct_data where id = #{id} limit 1
</select>
</mapper>
\ No newline at end of file
......
package com.skua.modules.business.service.impl;
import com.skua.core.service.IFactoryInfoService;
import com.skua.core.service.IPgQueryService;
import com.skua.modules.business.entity.WhatStructData;
import com.skua.modules.business.mapper.WhatStructDataMapper;
import com.skua.modules.business.service.IOlympicCenterService;
import com.skua.modules.business.vo.EchartResult;
import com.skua.modules.business.vo.TextResult;
import com.skua.modules.equip.mapper.FmEquipInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -19,104 +19,189 @@ import java.util.*;
@Service
public class OlympicCenterServiceImpl implements IOlympicCenterService {
// @Autowired
// private IPgQueryService pgQueryService;
@Autowired
private IPgQueryService pgQueryService;
@Autowired
private IFactoryInfoService factoryInfoService;
//queryReportData
@Autowired
private WhatStructDataMapper whatStructDataMapper;
private static String AT_ID = "A01A21A03";//奥体项目厂ID
@Override
public Map<String,Object> getRealTimeData(String sourceType) {
Map<String,Object> map = new HashMap<>();
// String jsFields = "BKYHWSC_JS_Tag2,BKYHWSC_JS_Tag3";
// List<Map<String, Object>> monitorList = pgQueryService.queryFactoryMonitorFromRealTimeData("",jsFields);
// if(monitorList.size()==1){
// map = monitorList.get(0);
// }
List<WhatStructData> list = whatStructDataMapper.getList();
Map<String, Object> monitorMap = new HashMap<>();
List<WhatStructData> pybList = new ArrayList<>();
List<WhatStructData> fybList = new ArrayList<>();
List<WhatStructData> wybList = new ArrayList<>();
List<TextResult> pList = new ArrayList<>();
List<TextResult> fList = new ArrayList<>();
List<TextResult> wList = new ArrayList<>();
if("feed".equals(sourceType)){//压力14流量8
for (int i = 0; i < 14; i++) {
TextResult textResult = new TextResult();
textResult.setTitle("压力表"+(i+1));
if(i==8){
textResult.setValue("0.04");
}else{
textResult.setValue("0.00");
}
pList.add(i,textResult);
}
for (int j = 0; j < 8; j++) {
TextResult textResult = new TextResult();
textResult.setTitle("流量计"+(j+1));
textResult.setValue("0.00");
fList.add(j,textResult);
String pgField = "";
if(sourceType==null){
for (WhatStructData whatStructData:list) {
pgField = pgField +","+whatStructData.getMonitorId();
}
map.put("pressure",pList);
map.put("flow",fList);
}else if("hot".equals(sourceType)){//压力10流量4温度4;
for (int i = 0; i < 10; i++) {
TextResult textResult = new TextResult();
textResult.setTitle("压力表"+(i+1));
textResult.setValue("0.00");
pList.add(i,textResult);
}
for (int j = 0; j < 4; j++) {
TextResult textResult = new TextResult();
textResult.setTitle("流量计"+(j+1));
textResult.setValue("0.00");
fList.add(j,textResult);
}
for (int k = 0; k < 4; k++) {
TextResult textResult = new TextResult();
textResult.setTitle("温度计"+(k+1));
textResult.setValue("--");
wList.add(k,textResult);
}
map.put("pressure",pList);
map.put("flow",fList);
map.put("temperature",wList);
}else if("fire".equals(sourceType)){//压力9流量2.
for (int i = 0; i < 9; i++) {
TextResult textResult = new TextResult();
textResult.setTitle("压力表"+(i+1));
textResult.setValue("0.00");
pList.add(i,textResult);
}
for (int j = 0; j < 2; j++) {
TextResult textResult = new TextResult();
textResult.setTitle("流量计"+(j+1));
textResult.setValue("0.00");
fList.add(j,textResult);
}
map.put("pressure",pList);
map.put("flow",fList);
}else{
for (int i = 0; i < 33; i++) {
TextResult textResult = new TextResult();
textResult.setTitle("压力表"+(i+1));
if(i==8){
textResult.setValue("0.041");
}else{
textResult.setValue("0.00");
for (WhatStructData whatStructData:list) {
if(sourceType.equals(whatStructData.getSystemCode())){
if("pressure".equals(whatStructData.getEquipType())){
pybList.add(whatStructData);
}else if("flow".equals(whatStructData.getEquipType())){
fybList.add(whatStructData);
}else if("temperature".equals(whatStructData.getEquipType())){
wybList.add(whatStructData);
}else{ }
pgField = pgField +","+whatStructData.getMonitorId();
}
pList.add(i,textResult);
}
for (int j = 0; j < 14; j++) {
TextResult textResult = new TextResult();
textResult.setTitle("流量计"+(j+1));
textResult.setValue("0.00");
fList.add(j,textResult);
}
for (int k = 0; k < 4; k++) {
TextResult textResult = new TextResult();
textResult.setTitle("温度计"+(k+1));
textResult.setValue("--");
wList.add(k,textResult);
}
List<Map<String, Object>> monitorList = pgQueryService.queryFactoryMonitorFromRealTimeData(AT_ID,pgField);
if(monitorList.size()==1){
monitorMap = monitorList.get(0);
if("feed".equals(sourceType)){//压力14流量8
for (int i = 0; i < 14; i++) {
TextResult textResult = new TextResult();
if(i<pybList.size()){
textResult.setTitle(pybList.get(i).getId());
if(monitorMap.get(pybList.get(i).getMonitorId())==null){
textResult.setValue("--");
}else{
double pResult = formatDouble(Double.parseDouble(monitorMap.get(pybList.get(i).getMonitorId()).toString())/1000);
textResult.setValue(String.valueOf(pResult));
}
}else{
textResult.setTitle("pressure"+(i+1));
textResult.setValue("--");
}
pList.add(i,textResult);
}
for (int j = 0; j < 8; j++) {
TextResult textResult = new TextResult();
if(j<fybList.size()){
textResult.setTitle(fybList.get(j).getId());
if(monitorMap.get(fybList.get(j).getMonitorId())==null){
textResult.setValue("--");
}else{
textResult.setValue(monitorMap.get(fybList.get(j).getMonitorId()).toString());
}
}else{
textResult.setTitle("flow"+(j+1));
textResult.setValue("--");
}
fList.add(j,textResult);
}
map.put("pressure",pList);
map.put("flow",fList);
}else if("hot".equals(sourceType)){//压力10流量4温度4;
for (int i = 0; i < 10; i++) {
TextResult textResult = new TextResult();
if(i<pybList.size()){
textResult.setTitle(pybList.get(i).getId());
if(monitorMap.get(pybList.get(i).getMonitorId())==null){
textResult.setValue("--");
}else{
double pResult = formatDouble(Double.parseDouble(monitorMap.get(pybList.get(i).getMonitorId()).toString())/1000);
textResult.setValue(String.valueOf(pResult));
}
}else{
textResult.setTitle("pressure"+(i+1));
textResult.setValue("--");
}
pList.add(i,textResult);
}
for (int j = 0; j < 4; j++) {
TextResult textResult = new TextResult();
if(j<fybList.size()){
textResult.setTitle(fybList.get(j).getId());
if(monitorMap.get(fybList.get(j).getMonitorId())==null){
textResult.setValue("--");
}else{
textResult.setValue(monitorMap.get(fybList.get(j).getMonitorId()).toString());
}
}else{
textResult.setTitle("flow"+(j+1));
textResult.setValue("--");
}
fList.add(j,textResult);
}
for (int k = 0; k < 4; k++) {
TextResult textResult = new TextResult();
if(k<wybList.size()){
textResult.setTitle(wybList.get(k).getId());
if(monitorMap.get(wybList.get(k).getMonitorId())==null){
textResult.setValue("--");
}else{
textResult.setValue(monitorMap.get(wybList.get(k).getMonitorId()).toString());
}
}else{
textResult.setTitle("temperature"+(k+1));
textResult.setValue("--");
}
wList.add(k,textResult);
}
map.put("pressure",pList);
map.put("flow",fList);
map.put("temperature",wList);
}else if("fire".equals(sourceType)){//压力9流量2.
for (int i = 0; i < 9; i++) {
TextResult textResult = new TextResult();
if(i<pybList.size()){
textResult.setTitle(pybList.get(i).getId());
if(monitorMap.get(pybList.get(i).getMonitorId())==null){
textResult.setValue("--");
}else{
double pResult = formatDouble(Double.parseDouble(monitorMap.get(pybList.get(i).getMonitorId()).toString())/1000);
textResult.setValue(String.valueOf(pResult));
}
}else{
textResult.setTitle("pressure"+(i+1));
textResult.setValue("--");
}
pList.add(i,textResult);
}
for (int j = 0; j < 2; j++) {
TextResult textResult = new TextResult();
if(j<fybList.size()){
textResult.setTitle(fybList.get(j).getId());
if(monitorMap.get(fybList.get(j).getMonitorId())==null){
textResult.setValue("--");
}else{
textResult.setValue(monitorMap.get(fybList.get(j).getMonitorId()).toString());
}
}else{
textResult.setTitle("flow"+(j+1));
textResult.setValue("--");
}
fList.add(j,textResult);
}
map.put("pressure",pList);
map.put("flow",fList);
}else{
for (int i = 0; i < 33; i++) {
TextResult textResult = new TextResult();
textResult.setTitle("pressure"+(i+1));
textResult.setValue("0.00");
pList.add(i,textResult);
}
for (int j = 0; j < 14; j++) {
TextResult textResult = new TextResult();
textResult.setTitle("flow"+(j+1));
textResult.setValue("0.00");
fList.add(j,textResult);
}
for (int k = 0; k < 4; k++) {
TextResult textResult = new TextResult();
textResult.setTitle("temperature"+(k+1));
textResult.setValue("--");
wList.add(k,textResult);
}
map.put("pressure",pList);
map.put("flow",fList);
map.put("temperature",wList);
}
map.put("pressure",pList);
map.put("flow",fList);
map.put("temperature",wList);
}
return map;
}
......@@ -166,30 +251,70 @@ public class OlympicCenterServiceImpl implements IOlympicCenterService {
@Override
public List<EchartResult> getPressureChart(String equipId,String type) {//p:压力 f:流量计 t:温度计
List<EchartResult> list = new ArrayList<>();
for (int i = 0; i < 30; i++) {
Calendar date = Calendar.getInstance();
date.add(Calendar.DATE, i-30);
String newDate = new SimpleDateFormat("yyyy-MM-dd").format(date.getTime()).substring(5,10);
EchartResult echartResult = new EchartResult();
echartResult.setName(newDate);
if("p".equals(type)){
echartResult.setValue(formatDouble(getRandom(0.40,0.50)).toString());
echartResult.setSeries("压力表");
}else if("f".equals(type)){
echartResult.setValue("0.00");
echartResult.setSeries("流量计");
}else if("t".equals(type)){
echartResult.setValue("0.00");
echartResult.setSeries("温度计");
}else{
WhatStructData whatStructData = whatStructDataMapper.getOneById(equipId);
if(whatStructData==null){
return list;
}
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -7);
String startDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
String start = startDate + " 00:00:00";
String endDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String end = endDate + " 23:59:59";
List<Map<String, Object>> dataList = factoryInfoService.queryReportData(AT_ID,whatStructData.getMonitorId(),start,end,"hour");
if(dataList.size()>0){
for (Map<String, Object> map:dataList) {
EchartResult echartResult = new EchartResult();
echartResult.setName(map.get("time").toString());
if("p".equals(type)){
double pResult = formatDouble(Double.parseDouble(map.get(whatStructData.getMonitorId()).toString())/1000);
echartResult.setValue(String.valueOf(pResult));
echartResult.setSeries("压力表");
}else if("f".equals(type)){
echartResult.setValue(map.get(whatStructData.getMonitorId()).toString());
echartResult.setSeries("流量计");
}else if("t".equals(type)){
echartResult.setValue(map.get(whatStructData.getMonitorId()).toString());
echartResult.setSeries("温度计");
}else{
echartResult.setValue("--");
echartResult.setSeries("--");
}
list.add(echartResult);
}
}else{
for (int i = 0; i < 30; i++) {
Calendar date = Calendar.getInstance();
date.add(Calendar.DATE, i-30);
String newDate = new SimpleDateFormat("yyyy-MM-dd").format(date.getTime()).substring(5,10);
EchartResult echartResult = new EchartResult();
echartResult.setName(newDate);
echartResult.setValue("--");
echartResult.setSeries("--");
if("p".equals(type)){
echartResult.setSeries("压力表");
}else if("f".equals(type)){
echartResult.setSeries("流量计");
}else if("t".equals(type)){
echartResult.setSeries("温度计");
}else{
echartResult.setSeries("--");
}
list.add(echartResult);
}
list.add(echartResult);
}
return list;
}
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -7);
String startDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
String start = startDate + " 00:00:00";
String endDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String end = endDate + " 23:59:59";
System.out.println(start+"-----"+end);
}
@Override
public Map<String, Object> getBzRealTimeData(String sourceType) {
Map<String,Object> map = new HashMap<>();
......@@ -267,42 +392,42 @@ public class OlympicCenterServiceImpl implements IOlympicCenterService {
public Map<String, Object> getRealTimeDataToUE() {
List<WhatStructData> list = whatStructDataMapper.getList();
Map<String, Object> map = new HashMap<>();
List<WhatStructData> pAtList = new ArrayList<>();
List<WhatStructData> fAtList = new ArrayList<>();
List<WhatStructData> wAtList = new ArrayList<>();
Map<String, Object> monitorMap = new HashMap<>();
String pgField = "";
for (WhatStructData whatStructData:list) {
if("pressure".equals(whatStructData.getEquipType())){
pAtList.add(whatStructData);
}else if("flow".equals(whatStructData.getEquipType())){
fAtList.add(whatStructData);
}else if("temperature".equals(whatStructData.getEquipType())){
wAtList.add(whatStructData);
}else{ }
pgField = pgField +","+whatStructData.getMonitorId();
}
for (int i = 0; i < pAtList.size(); i++) {
if("205".equals(pAtList.get(i).getId())){
map.put(pAtList.get(i).getId(),"0.04");
}else{
map.put(pAtList.get(i).getId(),"0.00");
List<Map<String, Object>> monitorList = pgQueryService.queryFactoryMonitorFromRealTimeData(AT_ID,pgField);
if(monitorList.size()==1){
monitorMap = monitorList.get(0);
for (WhatStructData whatStructData:list) {
if(whatStructData.getMonitorId()!=null){
if("pressure".equals(whatStructData.getEquipType())){
double pResult = formatDouble(Double.parseDouble(monitorMap.get(whatStructData.getMonitorId()).toString())/1000);
map.put(whatStructData.getId(),String.valueOf(pResult));
}else{
map.put(whatStructData.getId(),monitorMap.get(whatStructData.getMonitorId()));
}
}else{
map.put(whatStructData.getId(),"--");
}
}
}else{
for (WhatStructData whatStructData:list) {
map.put(whatStructData.getId(),"--");
}
}
for (int j = 0; j < fAtList.size(); j++) {
map.put(fAtList.get(j).getId(),"0.00");
}
for (int k = 0; k < wAtList.size(); k++) {
map.put(wAtList.get(k).getId(),"--");
}
return map;
}
public static void main(String[] args) {
for (int i = 0; i < 24; i++) {
Calendar date = Calendar.getInstance();
date.add(Calendar.HOUR, i-24);
String newDate = new SimpleDateFormat("HH:00").format(date.getTime());
System.out.println("=========="+newDate+"============");
}
}
// public static void main(String[] args) {
// for (int i = 0; i < 24; i++) {
// Calendar date = Calendar.getInstance();
// date.add(Calendar.HOUR, i-24);
// String newDate = new SimpleDateFormat("HH:00").format(date.getTime());
// System.out.println("=========="+newDate+"============");
// }
// }
/**
* 获取大于等于min,小于max的随机小数
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!