Commit dac7701f authored by shulidong's avatar shulidong

完善报告生成

parent 9578bb05
...@@ -28,7 +28,7 @@ public class AlertInfoController { ...@@ -28,7 +28,7 @@ public class AlertInfoController {
public BaseResponse<List<AlertInfoVo>> list(){ public BaseResponse<List<AlertInfoVo>> list(){
try { try {
docxService.fillDocx(); docxService.fillDocx("C0A001 - 1 - 1600756452620");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
......
package cn.wise.sc.energy.power.plant.business.controller; package cn.wise.sc.energy.power.plant.business.controller;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.wise.sc.energy.power.plant.business.domain.AutoInspection;
import cn.wise.sc.energy.power.plant.business.domain.BtreeInfoConfig; import cn.wise.sc.energy.power.plant.business.domain.BtreeInfoConfig;
import cn.wise.sc.energy.power.plant.business.domain.redisTrans.BtreeInerAct; import cn.wise.sc.energy.power.plant.business.domain.redisTrans.BtreeInerAct;
import cn.wise.sc.energy.power.plant.business.domain.redisTrans.BtreeInerAction; import cn.wise.sc.energy.power.plant.business.domain.redisTrans.BtreeInerAction;
...@@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.CrossOrigin; ...@@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -176,7 +178,7 @@ public class BtreeInspectionController { ...@@ -176,7 +178,7 @@ public class BtreeInspectionController {
@Autowired @Autowired
DocxService docxService; DocxService docxService;
@PostMapping("/reportDownload") @PostMapping("/reportDownload")
public BaseResponse fileDownload() { public BaseResponse fileDownload(@RequestBody AutoInspection info) {
OutputStream out = null; OutputStream out = null;
try { try {
response.setHeader("Content-Disposition", "attachment;filename=" + "demo1" + ".docx"); response.setHeader("Content-Disposition", "attachment;filename=" + "demo1" + ".docx");
...@@ -184,7 +186,7 @@ public class BtreeInspectionController { ...@@ -184,7 +186,7 @@ public class BtreeInspectionController {
out = response.getOutputStream(); out = response.getOutputStream();
byte[] by = docxService.fillDocx(); byte[] by = docxService.fillDocx(info.getId());
out.write(by); out.write(by);
out.close(); out.close();
return BaseResponse.okMsg("成功"); return BaseResponse.okMsg("成功");
......
...@@ -46,7 +46,7 @@ public class AutoInspection { ...@@ -46,7 +46,7 @@ public class AutoInspection {
public static void main(String[] args) { public static void main(String[] args) {
String a = "{\"name\": \"励端\", \"RunoutX\": {\"1X\": 1.47635805606842, \"2X\": 0.04492176324129105, \"3X\": 1.47635805606842}, \"RunoutY\": {\"1X\": 1.47635805606842, \"2X\": 0.04492176324129105, \"3X\": 1.47635805606842}, \"VibrateX\": {\"1X\": 1.47635805606842, \"2X\": 0.04492176324129105, \"3X\": 1.47635805606842}, \"VibrateY\": {\"1X\": 1.47635805606842, \"2X\": 0.04492176324129105, \"3X\": 1.47635805606842}, \"diagnosis\": \"机械不存在故障\"}"; String a = "{\"name\": \"励端\", \"RunoutX\": {\"1X\": 1.47635805606842, \"2X\": 0.04492176324129105, \"3X\": 1.47635805606842}, \"RunoutY\": {\"1X\": 1.47635805606842, \"2X\": 0.04492176324129105, \"3X\": 1.47635805606842}, \"VibrateX\": {\"1X\": 1.47635805606842, \"2X\": 0.04492176324129105, \"3X\": 1.47635805606842}, \"VibrateY\": {\"1X\": 1.47635805606842, \"2X\": 0.04492176324129105, \"3X\": 1.47635805606842}, \"diagnosis\": \"机械不存在故障\"}";
JSONObject jsonObject = JSON.parseObject(a); JSONObject jsonObject = JSON.parseObject(a);
jsonObject.get(""); JsonObject e = (JsonObject) jsonObject.get("RunoutX");
} }
} }
...@@ -10,6 +10,7 @@ import javax.persistence.Entity; ...@@ -10,6 +10,7 @@ import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient;
/** /**
* @description: 设备信息 * @description: 设备信息
...@@ -65,6 +66,9 @@ public class DeviceInfo extends AbstractEntity<String> { ...@@ -65,6 +66,9 @@ public class DeviceInfo extends AbstractEntity<String> {
@Column(name = "deviceparam") @Column(name = "deviceparam")
private String deviceParam; private String deviceParam;
@Transient
private String plantName;
@Override @Override
public String getId() { public String getId() {
return getDeviceId(); return getDeviceId();
......
...@@ -17,6 +17,12 @@ import java.util.List; ...@@ -17,6 +17,12 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class DeviceInfoVo extends EntityVo { public class DeviceInfoVo extends EntityVo {
public DeviceInfoVo(String deviceName, String plangName) {
this.deviceName = deviceName;
this.plangName = plangName;
}
/** /**
* 设备所在电站的标识 * 设备所在电站的标识
*/ */
...@@ -44,5 +50,7 @@ public class DeviceInfoVo extends EntityVo { ...@@ -44,5 +50,7 @@ public class DeviceInfoVo extends EntityVo {
private String deviceParam; private String deviceParam;
private String plangName;
private List<UnitInfoVo> unitInfoVos; private List<UnitInfoVo> unitInfoVos;
} }
package cn.wise.sc.energy.power.plant.business.repository; package cn.wise.sc.energy.power.plant.business.repository;
import cn.wise.sc.energy.power.plant.business.domain.DeviceInfo; import cn.wise.sc.energy.power.plant.business.domain.DeviceInfo;
import cn.wise.sc.energy.power.plant.business.domain.vo.DeviceInfoVo;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
/** /**
...@@ -15,4 +17,7 @@ public interface DeviceInfoRepository extends ...@@ -15,4 +17,7 @@ public interface DeviceInfoRepository extends
JpaRepository<DeviceInfo, String> , JpaRepository<DeviceInfo, String> ,
JpaSpecificationExecutor<DeviceInfo> { JpaSpecificationExecutor<DeviceInfo> {
@Query("select new cn.wise.sc.energy.power.plant.business.domain.vo.DeviceInfoVo(d.deviceName,p.plantName) from DeviceInfo d left join PlantInfo p on d.plantId = p.plantId where d.deviceId = ?1")
DeviceInfoVo queryOnedeviceInfo(String deviceno);
} }
...@@ -4,28 +4,23 @@ import cn.wise.sc.energy.power.plant.business.config.MyApplicationContextAware; ...@@ -4,28 +4,23 @@ import cn.wise.sc.energy.power.plant.business.config.MyApplicationContextAware;
import cn.wise.sc.energy.power.plant.common.core.bean.BaseResponse; import cn.wise.sc.energy.power.plant.common.core.bean.BaseResponse;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Header;
import io.jsonwebtoken.Jwts; import io.jsonwebtoken.Jwts;
import org.redisson.api.RBucket; import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient; import org.redisson.api.RedissonClient;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
import static cn.wise.sc.energy.power.plant.business.security.SecurityConstants.AUTHORIZATION_HEADER; import static cn.wise.sc.energy.power.plant.business.security.SecurityConstants.AUTHORIZATION_HEADER;
import static cn.wise.sc.energy.power.plant.business.security.SecurityConstants.SOCKET_TOKEN; import static cn.wise.sc.energy.power.plant.business.security.SecurityConstants.SOCKET_TOKEN;
...@@ -48,10 +43,10 @@ public class JWTFilter extends BasicAuthenticationFilter { ...@@ -48,10 +43,10 @@ public class JWTFilter extends BasicAuthenticationFilter {
final String token = this.getToken(request); final String token = this.getToken(request);
//设置websocket 子协议头 //设置websocket 子协议头
response.setHeader("Sec-WebSocket-Protocol",request.getHeader("Sec-WebSocket-Protocol")); response.setHeader("Sec-WebSocket-Protocol",request.getHeader("Sec-WebSocket-Protocol"));
if(true){ /*if(true){
filterChain.doFilter(request, response); filterChain.doFilter(request, response);
return; return;
} }*/
if(request.getServletPath().contains("/login")||request.getServletPath().contains("/plantInfo/allPlantInfo")){ if(request.getServletPath().contains("/login")||request.getServletPath().contains("/plantInfo/allPlantInfo")){
filterChain.doFilter(request, response); filterChain.doFilter(request, response);
return; return;
......
package cn.wise.sc.energy.power.plant.business.service.impl;
import cn.afterturn.easypoi.entity.ImageEntity;
import jdk.nashorn.internal.ir.ReturnNode;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.chart.ui.RectangleEdge;
import org.jfree.data.category.DefaultCategoryDataset;
import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author neo.shu
* @since 2020/9/28 14:13
* 二叉树报告service
*/
@Service
public class BtreeReportServiceImpl {
public Map fetchData() {
return null;
}
public Map<String, List<SpiderWebPoint>> simulateSpiderData() {
Map<String, List<SpiderWebPoint>> map = new HashMap<>();
List<SpiderWebPoint> a = new ArrayList<>();
a.add(new SpiderWebPoint("热工参数", 3.0));
a.add(new SpiderWebPoint("热工参数", 3.0));
a.add(new SpiderWebPoint("热工参数", 3.0));
return null;
}
/**
* 生成雷达图
* @param title
* @param data
* @return
*/
public ImageEntity spiderWebPlot(String title, Map<String, List<SpiderWebPoint>> data) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
data.forEach((key,value)->{
value.forEach(
item->{
dataset.setValue(item.getValue(),key,item.getColumnKey());
}
);
});
SpiderWebPlot spiderwebplot = new SpiderWebPlot(dataset);
JFreeChart jfreechart = new JFreeChart(title, TextTitle.DEFAULT_FONT, spiderwebplot, false);
LegendTitle legendtitle = new LegendTitle(spiderwebplot);
legendtitle.setPosition(RectangleEdge.TOP);
jfreechart.addSubtitle(legendtitle);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
ChartUtils.writeChartAsPNG(out, jfreechart, 400, 500);
} catch (IOException e) {
e.printStackTrace();
}
return new ImageEntity(out.toByteArray(), 200, 200);
}
@Data
@AllArgsConstructor
class SpiderWebPoint {
private String columnKey;
private double value;
}
}
package cn.wise.sc.energy.power.plant.business.task.async;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import java.util.concurrent.Future;
/**
* 执行耗时任务
*
* @author neo.shu
* @since 2020/10/07 08:30
*/
@Service
public class ReportParamsTask {
@Async
public Future<String> executeTimeConsumingOperation(TimeConsumingOperation operation, Object... args) {
Future<String> future;
try {
operation.operate(args);
return new AsyncResult<>("0");
} catch (Exception e) {
future = new AsyncResult<>(e.getMessage());
e.printStackTrace();
return future;
}
}
}
package cn.wise.sc.energy.power.plant.business.task.async;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
/**
* 耗时任务操作接口
*
* @author neo.shu
* @since 2020/10/07 08:13
*/
@FunctionalInterface
public interface TimeConsumingOperation {
void operate(Object... args) throws IOException;
Map<String, Future<String>> REPORT_TASKS_MAP = new ConcurrentHashMap<>();
}
...@@ -3,7 +3,9 @@ package cn.wise.sc.energy.power.plant.business.utils.poi; ...@@ -3,7 +3,9 @@ package cn.wise.sc.energy.power.plant.business.utils.poi;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.resource.ClassPathResource; import cn.hutool.core.io.resource.ClassPathResource;
import cn.wise.sc.energy.power.plant.business.domain.AutoInspection; import cn.wise.sc.energy.power.plant.business.domain.AutoInspection;
import cn.wise.sc.energy.power.plant.business.domain.vo.DeviceInfoVo;
import cn.wise.sc.energy.power.plant.business.repository.AutoInspectionRepository; import cn.wise.sc.energy.power.plant.business.repository.AutoInspectionRepository;
import cn.wise.sc.energy.power.plant.business.repository.DeviceInfoRepository;
import cn.wise.sc.energy.power.plant.common.core.exception.ResponseEnum; import cn.wise.sc.energy.power.plant.common.core.exception.ResponseEnum;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
...@@ -33,17 +35,28 @@ public class DocxService { ...@@ -33,17 +35,28 @@ public class DocxService {
@Autowired @Autowired
AutoInspectionRepository autoInspectionRepository; AutoInspectionRepository autoInspectionRepository;
private static final Logger LOGGER = LoggerFactory.getLogger(DocxService.class); @Autowired
ReportParamProcessor reportParamProcessor;
@Autowired
DeviceInfoRepository deviceInfoRepository;
public byte[] fillDocx() throws Exception { private static final Logger LOGGER = LoggerFactory.getLogger(DocxService.class);
List<AutoInspection> list = autoInspectionRepository.findAutoInspectionsById("C0A001 - 1 - 1600756452620"); public static void main(String[] args) {
String a = "C0A001 - 1 - 1600756452620";
String[] c = a.split("- ");
System.out.println();
}
public byte[] fillDocx(String id) throws Exception {
List<AutoInspection> list = autoInspectionRepository.findAutoInspectionsById(id);
if (CollectionUtil.isEmpty(list)) { if (CollectionUtil.isEmpty(list)) {
ResponseEnum.BUSINESS_ERROR.newException("未找到相应的报告项"); ResponseEnum.BUSINESS_ERROR.newException("未找到相应的报告项");
} }
JSONObject allin = new JSONObject();
reportParamProcessor.paramJson(allin,list,id.split("- ")[2]);
final InputStream inputStream = new ClassPathResource("templates/" + "demo1.docx").getStream(); final InputStream inputStream = new ClassPathResource("templates/" + "demo1.docx").getStream();
XWPFDocument document = new XWPFDocument(inputStream); XWPFDocument document = new XWPFDocument(inputStream);
//添加页眉 需要固定的文字(中文标点)在模板上->{{:text:date:date:}} //添加页眉 需要固定的文字(中文标点)在模板上->{{:text:date:date:}}
List<XWPFHeader> pageHeaders = document.getHeaderList(); List<XWPFHeader> pageHeaders = document.getHeaderList();
JSONObject original = new JSONObject(); JSONObject original = new JSONObject();
...@@ -78,17 +91,12 @@ public class DocxService { ...@@ -78,17 +91,12 @@ public class DocxService {
tables.add(table); tables.add(table);
} }
} }
JSONObject allin = new JSONObject();
JSONObject fuzhu = new JSONObject();
fuzhu.put("MKW05CP001", 12.578);
allin.put("fuzhu", fuzhu);
JSONObject reportInfo = new JSONObject(); JSONObject reportInfo = new JSONObject();
reportInfo.put("username", "张三"); DeviceInfoVo deviceInfo = deviceInfoRepository.queryOnedeviceInfo(list.get(0).getDeviceid());
reportInfo.put("a", "张三"); reportInfo.put("plantName", deviceInfo.getPlangName());
reportInfo.put("date", LocalDateTime.now().format(DateTimeFormatter.BASIC_ISO_DATE).toString()); reportInfo.put("deviceName", deviceInfo.getDeviceName());
reportInfo.put("score", "暂未获取");
allin.put("reportInfo", reportInfo); allin.put("reportInfo", reportInfo);
...@@ -96,12 +104,13 @@ public class DocxService { ...@@ -96,12 +104,13 @@ public class DocxService {
PoiiUtiil.paragraph(texts, allin); PoiiUtiil.paragraph(texts, allin);
PoiiUtiil.table(tables, allin); PoiiUtiil.table(tables, allin);
//要求word在打开时提示更新域 //要求word在打开时提示更新域
document.enforceUpdateFields(); //document.enforceUpdateFields();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
FileOutputStream fos = new FileOutputStream("D:/"+ "生成文件.docx"); FileOutputStream fos = new FileOutputStream("D:/"+ "生成文件.docx");
document.write(fos); document.write(byteArrayOutputStream);
fos.flush(); fos.flush();
fos.close(); fos.close();
return byteArrayOutputStream.toByteArray();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
package cn.wise.sc.energy.power.plant.business.utils.poi;
import cn.hutool.core.collection.CollectionUtil;
import cn.wise.sc.energy.power.plant.business.domain.AutoInspection;
import cn.wise.sc.energy.power.plant.business.domain.DeviceInfo;
import cn.wise.sc.energy.power.plant.business.domain.vo.DeviceInfoVo;
import cn.wise.sc.energy.power.plant.business.service.ICharacterParamService;
import cn.wise.sc.energy.power.plant.business.task.async.ReportParamsTask;
import cn.wise.sc.energy.power.plant.business.task.async.TimeConsumingOperation;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonArray;
import net.opentsdb.client.api.query.response.QueryResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import static cn.wise.sc.energy.power.plant.business.task.async.TimeConsumingOperation.REPORT_TASKS_MAP;
/**
* 报告参数处理类
*
* @author neo.shu
* @since 2020/10/7 08:22
*/
@Service
public class ReportParamProcessor {
@Autowired
ICharacterParamService iCharacterParamService;
@Autowired
private ReportParamsTask reportParamsTask;
String[] subsidiaryParams = new String[]{
"CBA00MKF26S101",
"MKW05CP101",
"MKW05CP001",
"MKF16CF101",
"MKD12CT603A",
"MKD11CT603A",
"MKF23CQ101A",
"MKF23CQ101B",
"MKF26S102",
"MKG35CQ101",
"MKG30CQ112",
"MKW17CP001",
"MKW18CP001",
"MKW02CP001",
"MKW03CP001",
"MKW14CT001",
"MKW24CT001",
"MKA32CQ901A",
"MKA32CQ901B",
"MKG50CM102",
"MKA32CQ901C",
"MKA32CQ902",
"MKA32CQ903",
};
String[] electricParams = new String[]{
"MKA62CE601",
"MKA62CE602",
"MKA62CE603",
"MKA62CE604",
"MKA62CE605",
"MKA62CE705",
"MKA62CE704",
"MKA62CE604",
"MKA62CE605",
};
String[] environParams = new String[]{
"MKA51CQ101A",
"MKA51CQ101B",
"MKA51CQ101C",
"MKA51CQ102A",
"MKA51CQ102B",
"MKA51CQ102C",
"MKA52CQ101",
"MKA52CQ102",
"MKA52CQ103",
"MKA52CQ104",
"MKA52CQ105",
"MKA41CL001",
"MKA42CL001",
"MKA43CL001",
"MKA44CL001"
};
String[] stateParams = new String[]{
"MKA01CE003A",
"MKA16CS101",
"MKA01CE002A",
"MKA01CE001A",
"MKC20CE001",
"MKC20CE002",
};
public JSONObject paramJson(JSONObject allin, List<AutoInspection> list, String endTime) {
String deviceCode = list.get(0).getDeviceid();
//辅助参数
REPORT_TASKS_MAP.put("fuzhu_subsidiary" + endTime + deviceCode, reportParamsTask.executeTimeConsumingOperation(new Subsidiaryparam(), "fuzhu", allin, subsidiaryParams, deviceCode, endTime));
//电气参数
REPORT_TASKS_MAP.put("dianqi_subsidiary" + endTime + deviceCode, reportParamsTask.executeTimeConsumingOperation(new Subsidiaryparam(), "dianqi", allin, electricParams, deviceCode, endTime));
//环境参数
REPORT_TASKS_MAP.put("huanjing_subsidiary" + endTime + deviceCode, reportParamsTask.executeTimeConsumingOperation(new Subsidiaryparam(), "huanjing", allin, environParams, deviceCode, endTime));
//总体状态
REPORT_TASKS_MAP.put("zhuangtai_subsidiary" + endTime + deviceCode, reportParamsTask.executeTimeConsumingOperation(new Subsidiaryparam(), "state", allin, stateParams, deviceCode, endTime));
REPORT_TASKS_MAP.put("resultanalysis_subsidiary" + endTime + deviceCode, reportParamsTask.executeTimeConsumingOperation(new ResultAnalysis(), allin, list));
REPORT_TASKS_MAP.forEach((k, v) -> {
if (k.contains("_subsidiary" + endTime + deviceCode)) {
try {
v.get();
TimeConsumingOperation.REPORT_TASKS_MAP.remove(k);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
});
return allin;
}
/**
* 处理autoinspection 结论
*/
class ResultAnalysis implements TimeConsumingOperation {
@Override
public void operate(Object... args) throws IOException {
JSONObject jsonObject = (JSONObject) args[0];
List<AutoInspection> list = (List<AutoInspection>) args[1];
JSONObject results = new JSONObject();
Map<String, List<AutoInspection>> groupMap = list.stream().collect(Collectors.groupingBy(c -> c.getTyped()));
groupMap.forEach((k, v) -> {
List<AutoInspection> result_1 = v.stream().filter(item -> item.getResult().equals(1)).collect(Collectors.toList());
//非M的获取相应的结论
if (!k.equals("M")) {
if (!CollectionUtil.isEmpty(result_1)) {
//获取所有的报警结论
String result = "";
for (AutoInspection a : result_1) {
result += JSONObject.parseObject(a.getDiagnosis()).get("diagnosis") + " ";
}
results.put(k, result);
} else {
results.put(k, "根据系统智能诊断结果,本体温升正常、无报警");
}
}
if (k.equals("M")) {
for (AutoInspection a : v) {
JSONObject diagnosis = JSONObject.parseObject(a.getDiagnosis());
String name = (String) diagnosis.get("name");
String result = (String) diagnosis.get("diagnosis");
switch (name) {
case "励端":
//轴振
results.put("MZ", a.getResult() == 1 ? result : "根据系统智能诊断结果,5\\6\\7轴振振均在优秀运行范围");
break;
case "汽端":
//瓦振
results.put("MW", a.getResult() == 1 ? result : "根据系统智能诊断结果,5\\6\\7瓦振均在优秀运行范围");
break;
case "集电环":
//端振
results.put("MD", a.getResult() == 1 ? result : "根据系统智能诊断结果,汽、励端端部振动均在合格运行范围");
break;
}
jsonObject.put(name + "RunoutX", (JSONObject)diagnosis.get("RunoutX"));
jsonObject.put(name + "RunoutY", (JSONObject)diagnosis.get("RunoutY"));
}
}
});
jsonObject.put("result", results);
}
}
/**
* 获取参数相关值
*
* @return
*/
class Subsidiaryparam implements TimeConsumingOperation {
@Override
public void operate(Object... args) throws IOException {
String keyname = (String) args[0];
JSONObject jsonObject = (JSONObject) args[1];
String[] kkscode = (String[]) args[2];
String deviceCode = (String) args[3];
String endTime = (String) args[4];
//拼接kkscode
List<String> listWithDevicode = Arrays.stream(kkscode).map(item -> {
return deviceCode + item;
}).collect(Collectors.toList());
//查询opentsdb
QueryResponse response = iCharacterParamService.getRealTimeDataByKksCode(listWithDevicode, (Long.parseLong(endTime) - 1) + "", endTime, null);
//组装参数
JSONObject fuzhu = new JSONObject();
if (!CollectionUtil.isEmpty(response.getResults())) {
response.getResults().forEach(item -> {
LinkedHashMap result = item.getDps();
if (!CollectionUtil.isEmpty(result)) {
fuzhu.put(item.getMetric().split(deviceCode)[1], result.values().toArray()[0]);
} else {
fuzhu.put(item.getMetric().split(deviceCode)[1], 0.0);
}
});
}
jsonObject.put(keyname, fuzhu);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment