|
@@ -1,10 +1,19 @@
|
|
|
package com.hb.proj.analysis.controller;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -15,28 +24,37 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import com.hb.proj.allconfig.AccessToken;
|
|
|
import com.hb.proj.allconfig.SysLog;
|
|
|
-import com.hb.proj.analysis.service.DiagramDetecter;
|
|
|
import com.hb.proj.analysis.service.DiagramDiagnoseService;
|
|
|
+import com.hb.proj.analysis.service.DiagramFeatureDetecter;
|
|
|
import com.hb.proj.base.service.WellParamService;
|
|
|
import com.hb.proj.constant.SortCodeConstant;
|
|
|
import com.hb.proj.data.controller.DataTransUtils;
|
|
|
import com.hb.proj.data.service.DiagramDataService;
|
|
|
+import com.hb.proj.diagram.diagnose.DiagramChartBuilder;
|
|
|
+import com.hb.proj.diagram.diagnose.DiagramSimilarDetecter;
|
|
|
import com.hb.proj.model.DiagramDiagnoseStandardPO;
|
|
|
import com.hb.proj.model.DiagramDiagnoseStandardVO;
|
|
|
import com.hb.proj.model.DiagramFeature;
|
|
|
import com.hb.proj.model.MultiDataVO;
|
|
|
import com.hb.proj.model.WellParamPO;
|
|
|
+import com.hb.proj.sys.service.UploadService;
|
|
|
import com.hb.proj.utils.RequestParams;
|
|
|
import com.hb.proj.utils.RespVO;
|
|
|
import com.hb.proj.utils.RespVOBuilder;
|
|
|
import com.hb.xframework.dao.util.PageModel;
|
|
|
+import com.hb.xframework.util.DateUtil;
|
|
|
+import com.hb.xframework.util.MapUtils;
|
|
|
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.validation.constraints.NotBlank;
|
|
|
+import jakarta.validation.constraints.NotNull;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/diagnose/standard")
|
|
|
@Validated
|
|
|
public class DiagramDiagnoseController {
|
|
|
+
|
|
|
+ private final static Logger logger = LoggerFactory.getLogger(DiagramDiagnoseController.class);
|
|
|
|
|
|
@Autowired
|
|
|
private DiagramDiagnoseService service;
|
|
@@ -47,6 +65,9 @@ public class DiagramDiagnoseController {
|
|
|
@Autowired
|
|
|
private DiagramDataService diagramService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UploadService fileService;
|
|
|
+
|
|
|
@Value("${upload.access.path}")
|
|
|
private String accessPathPre;
|
|
|
|
|
@@ -143,7 +164,7 @@ public class DiagramDiagnoseController {
|
|
|
MultiDataVO diagramGatherData=diagramService.get(wparam.getParamId(), diagramTime);
|
|
|
DataTransUtils.convert(wparam,diagramGatherData);
|
|
|
|
|
|
- DiagramDetecter.extractFeature(diagramGatherData, feature);
|
|
|
+ DiagramFeatureDetecter.extractFeature(diagramGatherData, feature);
|
|
|
|
|
|
feature.setModifyBy(token.getUsName());
|
|
|
if(StringUtils.isNotBlank(feature.getFeatureId())) {
|
|
@@ -182,9 +203,14 @@ public class DiagramDiagnoseController {
|
|
|
diagramData.setOths(convert(oths));
|
|
|
|
|
|
DiagramFeature feature=service.getDiagramFeatureByWell(wellId);
|
|
|
- return RespVOBuilder.ok(DiagramDetecter.detect(diagramData, feature));
|
|
|
+ return RespVOBuilder.ok(DiagramFeatureDetecter.detect(diagramData, feature));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 字符序列转list
|
|
|
+ * @param serial
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private List<Double> convert(String serial){
|
|
|
String[] datas=serial.split(",");
|
|
|
List<Double> rst=new ArrayList<>(datas.length);
|
|
@@ -194,4 +220,127 @@ public class DiagramDiagnoseController {
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手动诊断指定功图
|
|
|
+ * @param request
|
|
|
+ * @param wellId
|
|
|
+ * @param diagramTime
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/startDiagnose")
|
|
|
+ public RespVO<Object> startDiagnose(HttpServletRequest request,String wellId,Date diagramTime){
|
|
|
+ PageModel<DiagramDiagnoseStandardVO> paged= service.query(null, 1, 100);
|
|
|
+ List<DiagramDiagnoseStandardVO> stds=paged.getData();
|
|
|
+
|
|
|
+ String srcChart=createDiagramChart(request,wellId,diagramTime,null);
|
|
|
+ String basePath=request.getSession().getServletContext().getRealPath("");
|
|
|
+
|
|
|
+ double minVal=Double.MAX_VALUE,temp=0;
|
|
|
+ DiagramDiagnoseStandardVO minVO=stds.get(0);
|
|
|
+ for(DiagramDiagnoseStandardVO std : stds) {
|
|
|
+ temp=DiagramSimilarDetecter.calcSimilary(basePath+std.getAccessPath(),srcChart);
|
|
|
+ logger.info("与模板功图【{}】,相似度{}",std.getConclusion(), temp);
|
|
|
+ if(temp<minVal) {
|
|
|
+ minVO=std;
|
|
|
+ minVal=temp;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //FileUtils.deleteQuietly(FileUtils.getFile(srcChart));
|
|
|
+
|
|
|
+ return RespVOBuilder.ok(minVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 指定功图转为模板功图
|
|
|
+ * @param request
|
|
|
+ * @param wellId
|
|
|
+ * @param diagramTime
|
|
|
+ * @param conclusion
|
|
|
+ * @param token
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @RequestMapping("/convert2TempDiagram")
|
|
|
+ public RespVO<Object> convert2TempDiagram(HttpServletRequest request, @NotBlank(message = "缺少井号") String wellId,
|
|
|
+ @NotNull(message = "缺少功图时间") Date diagramTime, @NotBlank(message = "缺少诊断结论") String conclusion,AccessToken token) throws IOException {
|
|
|
+
|
|
|
+ String destDir="upload"+File.separator+"diagnose"+File.separator+DateUtil.format(new Date(), "yyyyMM");
|
|
|
+ String chartPath=createDiagramChart(request,wellId,diagramTime,destDir);
|
|
|
+
|
|
|
+ //String basePath=request.getSession().getServletContext().getRealPath("");
|
|
|
+
|
|
|
+ //FileUtils.moveFileToDirectory(new File(chartPath), new File(basePath+destDir), true);
|
|
|
+
|
|
|
+ String fileName=chartPath.substring(chartPath.lastIndexOf("\\")+1);
|
|
|
+ String usName=token!=null?token.getUsName():"unknow";
|
|
|
+ chartPath=destDir+File.separator+fileName;
|
|
|
+
|
|
|
+ Map<String,Object> newFile=MapUtils.build("fileName",fileName,"filePath",chartPath,"accessPath","/"+chartPath.replaceAll("\\\\", "/"),"useFor","功图诊断模板","createBy",usName);
|
|
|
+ String fileId=fileService.addFile(newFile);
|
|
|
+
|
|
|
+ DiagramDiagnoseStandardPO std=new DiagramDiagnoseStandardPO();
|
|
|
+ std.setConclusion(conclusion);
|
|
|
+ std.setFileId(fileId);
|
|
|
+ std.setCreateBy(usName);
|
|
|
+ std.setModifyBy(usName);
|
|
|
+ service.add(std);
|
|
|
+ return RespVOBuilder.ok("详情请在功图诊断标准中查看");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对指定功图进行图片生成(存于服务器)
|
|
|
+ * @param request
|
|
|
+ * @param wellId
|
|
|
+ * @param diagramTime
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/buildDiagramChart")
|
|
|
+ public RespVO<Object> buildDiagramChart(HttpServletRequest request,String wellId,Date diagramTime){
|
|
|
+ createDiagramChart(request,wellId,diagramTime,null);
|
|
|
+ return RespVOBuilder.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据功图数据生成图片(存于服务器)
|
|
|
+ * @param request
|
|
|
+ * @param wellId
|
|
|
+ * @param diagramTime
|
|
|
+ * @param sortPath
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String createDiagramChart(HttpServletRequest request,String wellId,Date diagramTime,String sortPath) {
|
|
|
+ WellParamPO wparam=wpService.get(wellId, SortCodeConstant.PARAM_DIAGRAM_LOAD);
|
|
|
+ MultiDataVO diagramData=diagramService.get(wparam.getParamId(), diagramTime);
|
|
|
+ diagramData.setDisps(convert(diagramData.getDataVal1()));
|
|
|
+ diagramData.setOths(convert(diagramData.getDataVal2()));
|
|
|
+
|
|
|
+ if(diagramData.getStroke()==null) { //为兼容前期采集数据中没有此数据
|
|
|
+ diagramData.setStroke(Collections.max(diagramData.getDisps()));
|
|
|
+ }
|
|
|
+ if(diagramData.getGlbMax()==null) { //为兼容前期采集数据中没有此数据
|
|
|
+ diagramData.setGlbMax(Collections.max(diagramData.getOths()));
|
|
|
+ }
|
|
|
+ if(diagramData.getGlbMin()==null) { //为兼容前期采集数据中没有此数据
|
|
|
+ diagramData.setGlbMin(Collections.min(diagramData.getOths()));
|
|
|
+ }
|
|
|
+
|
|
|
+ String basePath=request.getSession().getServletContext().getRealPath("");
|
|
|
+ basePath+=StringUtils.isNotBlank(sortPath)?sortPath:("upload"+File.separator+"temp");
|
|
|
+ String fullName=basePath+File.separator+UUID.randomUUID()+".png";
|
|
|
+ try(FileOutputStream fout=FileUtils.openOutputStream(new File(fullName))) {
|
|
|
+ DiagramChartBuilder.writeDiagramAsJPEG(fout, diagramData);
|
|
|
+
|
|
|
+ fout.flush();
|
|
|
+ fout.close();
|
|
|
+ }
|
|
|
+ catch(IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return fullName;
|
|
|
+ }
|
|
|
}
|