瀏覽代碼

增加功图绘制数据接口

chenwen 2 年之前
父節點
當前提交
8c490c995e

+ 4 - 0
src/main/java/com/hb/proj/base/service/WellParamService.java

@@ -89,6 +89,10 @@ public class WellParamService {
 		return dao.queryForPojo("select * from tzl_well_param  where del_if=false and param_id=?",WellParamPO.class,paramId);
 	}
 	
+	public WellParamPO get(String wellId,String paramCode) {
+		return dao.queryForPojo("select * from tzl_well_param  where del_if=false and well_id=? and param_code=?",WellParamPO.class,wellId,paramCode);
+	}
+	
 	
 	
 	public boolean update(WellParamPO param) {

+ 6 - 0
src/main/java/com/hb/proj/constant/SortCodeConstant.java

@@ -1,6 +1,12 @@
 package com.hb.proj.constant;
 
+import java.util.Map;
+
+import com.hb.xframework.util.MapUtils;
+
 public class SortCodeConstant {
 
+	public static final String PARAM_FREQ="freq";
 	
+	public static final Map<String,Object> paramType=MapUtils.build("diagram_load","GT","diagram_current","DL","diagram_power","DGL");
 }

+ 110 - 0
src/main/java/com/hb/proj/data/controller/DiagramDataController.java

@@ -0,0 +1,110 @@
+package com.hb.proj.data.controller;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.hb.proj.base.service.WellParamService;
+import com.hb.proj.base.service.WellService;
+import com.hb.proj.constant.SortCodeConstant;
+import com.hb.proj.data.service.DiagramDataService;
+import com.hb.proj.data.service.ParamDataService;
+import com.hb.proj.model.GatherDataPO;
+import com.hb.proj.model.MultiGatherPO;
+import com.hb.proj.model.WellParamPO;
+import com.hb.proj.model.WellVO;
+import com.hb.proj.utils.RespVO;
+import com.hb.proj.utils.RespVOBuilder;
+import com.hb.xframework.util.DateUtil;
+import com.hb.xframework.util.MapUtils;
+
+import jakarta.validation.constraints.NotBlank;
+
+@RestController
+@RequestMapping("/diagram")
+@Validated
+public class DiagramDataController {
+
+	@Autowired
+	private WellService  wellService;
+	
+	@Autowired
+	private WellParamService  wpService;
+	
+	@Autowired
+	private DiagramDataService  diagramService;
+	
+	@Autowired
+	private ParamDataService   paramDataService;
+	
+	
+	/**
+	 * 获得功图绘制数据
+	 * @param wellId
+	 * @param paramCode
+	 * @param action
+	 * @param refTime
+	 * @return
+	 */
+	@RequestMapping("/getDrawData")
+	public RespVO<Object> getDrawData(@NotBlank(message = "缺少井记录号") String wellId,
+			@NotBlank(message = "缺少采集参数编码") String paramCode,String action ,Date refTime){
+		
+		WellParamPO wparam=wpService.get(wellId, paramCode);
+		MultiGatherPO  diagram=diagramService.get(wparam.getParamId(), refTime, action);
+		if(diagram==null) {
+			return RespVOBuilder.error("无数据");
+		}
+		GatherDataUtils.convert(wparam,diagram);
+		
+		WellVO well=wellService.get(wellId);
+		WellParamPO  freqParam=wpService.get(wellId, SortCodeConstant.PARAM_FREQ);
+		GatherDataPO freqPO=paramDataService.getRefFreq(freqParam.getParamId(), diagram.getGatherTime());
+		GatherDataUtils.convert(freqParam, freqPO);
+		String freqDesc=freqPO!=null?(freqPO.getDispDataVal()+freqParam.getDisplayUnit()):"";
+		
+		return RespVOBuilder.ok(buildData(well,wparam,diagram,freqDesc));
+	}
+	
+	private Map<String,Object>  buildData(WellVO well,WellParamPO wparam,MultiGatherPO  diagram,String freq){
+		String smpTime=DateUtil.format(diagram.getGatherTime(),"yyyy-MM-dd HH:mm:ss");
+		String[] dtstr=smpTime.split(" ");
+		Map<String,Object> base=new HashMap<String,Object>();
+		base.put("xTitle", wparam.getSerialName2()+"("+wparam.getDisplayUnit2()+")");
+		base.put("yTitle", wparam.getSerialName()+"("+wparam.getDisplayUnit()+")");
+		base.put("xUnit",  wparam.getDisplayUnit2());
+		base.put("yUnit", wparam.getDisplayUnit());
+		base.put("title",  "时间: "+dtstr[1]);
+		base.put("type",  SortCodeConstant.paramType.get(wparam.getParamCode()));
+		
+		String[] descTxt= {"隶属单位:"+well.getBelongOrgName(),"井名:"+well.getWellName(),"测试日期:"+dtstr[0],"冲次:"+freq};
+		
+		Map<String,Object> serial=new HashMap<String,Object>();
+		serial.put("xvals", diagram.getSerial1());
+		serial.put("yvals", diagram.getSerial2());
+		
+		return MapUtils.build("base",base,"serial",serial,"descTxt",descTxt);
+		
+	}
+	
+	/*
+	private Map<String,Object>  buildData(){
+		String nowstr=DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss");
+		Map<String,Object> base=MapUtils.build("xTitle","位移(m)","yTitle","负荷(kN)","xUnit","m","yUnit","kN","title","CQ-2 2019-09-09","type","GT");
+		Map<String,Object> serial=MapUtils.build("smpTime",nowstr);
+		double[] x= {0.2,1.0,2.0,3.0,4.0,5.0,3.0,2.0,1.0};
+		double[] y= {15.4,28,34,44,50,18,38,66,32};
+		serial.put("xvals", x);
+		serial.put("yvals", y);
+		
+		String[] dtstr=nowstr.split(" ");
+		String[] descTxt= {"时间: "+dtstr[1],"隶属单位:特油组","井名:杜84","测试日期:"+dtstr[0],"冲次:"};
+		
+		return MapUtils.build("base",base,"serial",serial,"descTxt",descTxt);
+	}*/
+}

+ 41 - 2
src/main/java/com/hb/proj/data/controller/GatherDataUtils.java

@@ -1,11 +1,13 @@
 package com.hb.proj.data.controller;
 
 import java.text.DecimalFormat;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.lang3.StringUtils;
 
 import com.hb.proj.model.GatherDataPO;
+import com.hb.proj.model.MultiGatherPO;
 import com.hb.proj.model.WellParamPO;
 
 public class GatherDataUtils {
@@ -13,7 +15,7 @@ public class GatherDataUtils {
 	public static DecimalFormat df=new DecimalFormat("0.00");
 
 	/**
-	 * 对单井单采集值进行单位转换、格式化处理
+	 * 单参数单采集值进行单位转换、格式化处理
 	 * @param wp
 	 * @param gdata
 	 */
@@ -32,7 +34,7 @@ public class GatherDataUtils {
 	}
 	
 	/**
-	 * 对单井数多采集值进行单位转换、格式化处理
+	 * 单参数多采集值进行单位转换、格式化处理
 	 * @param wp
 	 * @param gdatas
 	 */
@@ -46,4 +48,41 @@ public class GatherDataUtils {
 		
 		
 	}
+	
+	/**
+	 * 单个图形数据转换、格式化
+	 * @param wp
+	 * @param gdata
+	 */
+	public static void convert(WellParamPO wp,MultiGatherPO gdata) {
+		if(gdata==null||StringUtils.isBlank(gdata.getDataVal1())||StringUtils.isBlank(gdata.getDataVal2())) {
+			return;
+		}
+		gdata.setSerial1(convertForDiagram(gdata.getDataVal1(),wp.getDisplayFormat2(),wp.getDisInsScale2()));
+		gdata.setSerial2(convertForDiagram(gdata.getDataVal2(),wp.getDisplayFormat(),wp.getDisInsScale()));
+		
+	}
+	
+	/**
+	 * 图形数据  单个序列数据的转换、格式化
+	 * @param dstr
+	 * @param fmt
+	 * @param scale
+	 * @return
+	 */
+	private static List<Double> convertForDiagram(String dstr,String fmt,Double scale) {
+		if(scale==null) {
+			scale=1.0;
+		}
+		if(StringUtils.isNotBlank(fmt)) {
+			df.applyPattern(fmt);
+		}
+		String[] ds=dstr.split(",");
+		List<Double> serial=new ArrayList<Double>(ds.length);
+		for(String d : ds) {
+			serial.add(Double.parseDouble(df.format(Double.parseDouble(d)*scale)));
+		}
+		
+		return serial;
+	}
 }

+ 41 - 0
src/main/java/com/hb/proj/data/service/DiagramDataService.java

@@ -0,0 +1,41 @@
+package com.hb.proj.data.service;
+
+import java.util.Date;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.hb.proj.model.MultiGatherPO;
+import com.hb.xframework.dao.core.SpringJdbcDAO;
+
+@Service
+public class DiagramDataService {
+
+	@Autowired
+	private SpringJdbcDAO  dao;
+	
+	public MultiGatherPO   get(String paramId,Date refTime,String action) {
+		String sql="select %s from tzl_gather_data_multi where well_param=? and %s";
+		if("pre".equals(action)) {
+			sql=String.format(sql, "max(gather_time)","gather_time < ?");
+		}
+		else if("next".equals(action)) {
+			sql=String.format(sql, "min(gather_time)","gather_time > ?");
+		}
+		else{  //last
+			sql=String.format(sql, "max(gather_time)","gather_time > date_add(?,INTERVAL -30 DAY)");
+			refTime=new Date();
+		}
+		Date gatherDate=dao.queryForObject(sql,Date.class, paramId, refTime);
+		return gatherDate==null?null:get(paramId,gatherDate);
+	}
+	
+	public MultiGatherPO   get(String paramId,Date gatherTime) {
+		String sql="""
+					select well_param,gather_time,data_val1,data_val2 from tzl_gather_data_multi 
+					where well_param=?  and gather_time=?  
+					limit 1
+				""";
+		return dao.queryForPojo(sql, MultiGatherPO.class, paramId,gatherTime);
+	}
+}

+ 34 - 0
src/main/java/com/hb/proj/data/service/ParamDataService.java

@@ -1,6 +1,8 @@
 package com.hb.proj.data.service;
 
 import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -15,6 +17,22 @@ public class ParamDataService {
 	@Autowired
 	private SpringJdbcDAO  dao;
 	
+	/**
+	 * 图形数据中的冲次,指定时间附近的单个值
+	 * @param paramId
+	 * @param refTime
+	 * @return
+	 */
+	public GatherDataPO  getRefFreq(String paramId, Date refTime) {
+		String sql="""
+				  select data_val
+				  from tzl_gather_data d
+				  where well_param=? and gather_time between date_add(?,INTERVAL -30 MINUTE) and ?
+				  limit 1
+				""";
+		return dao.queryForPojo(sql, GatherDataPO.class, paramId,refTime,refTime);
+	}
+	
 	public PageModel<GatherDataPO> queryHisData(String paramId,Date startDate,Date endDate,int pageNo,int pageSize){
 		String sql="""
 					select gather_time,data_val,alarm_desc 
@@ -37,4 +55,20 @@ public class ParamDataService {
 				""";
 		return dao.queryForPagedData(sql, pageNo, pageSize, GatherDataPO.class, paramId,startDate,endDate);
 	}
+	
+	public PageModel<Map<String,Object>> queryMultiParamHisData(String mainParamId,List<String> othParamIds,Date startDate,Date endDate,int pageNo,int pageSize){
+		StringBuilder subSQL=new StringBuilder();
+		for(String paramId : othParamIds) {
+			subSQL.append("(select data_val from tzl_gather_data d2 where well_param='"+paramId+"'");
+			subSQL.append(" and d2.gather_time between DATE_ADD(d.gather_time,INTERVAL -1 MINUTE) and DATE_ADD(d.gather_time,INTERVAL -1 MINUTE) limit 1) as "+paramId);
+		}
+		String sql="""
+					select gather_time,data_val,
+				"""+ subSQL.toString()+
+				"""
+					from tzl_gather_data d
+					where d.well_param=? and gather_time between ? and ?
+				""";
+		return dao.queryForPagedData(sql, pageNo, pageSize, mainParamId,startDate,endDate);
+	}
 }

+ 23 - 0
src/main/java/com/hb/proj/model/MultiGatherPO.java

@@ -0,0 +1,23 @@
+package com.hb.proj.model;
+
+import java.util.Date;
+import java.util.List;
+
+import lombok.Data;
+
+@Data
+public class MultiGatherPO {
+
+	private String wellParam;
+	
+	private Date gatherTime;
+	
+	private String dataVal1;
+	
+	private String dataVal2;
+	
+	private List<Double> serial1;
+	
+	private List<Double> serial2;
+	
+}

+ 4 - 0
src/main/java/com/hb/proj/model/WellParamPO.java

@@ -64,6 +64,10 @@ public class WellParamPO {
 	private Double gatInsScale2;
 	
 	private String displayFormat2;
+	
+	private String serialName;
+	
+	private String serialName2;
 
 	
 }