DiagramDataController.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.hb.proj.data.controller;
  2. import java.util.Date;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.validation.annotation.Validated;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import com.hb.proj.base.service.WellParamService;
  10. import com.hb.proj.base.service.WellService;
  11. import com.hb.proj.constant.SortCodeConstant;
  12. import com.hb.proj.data.service.DiagramDataService;
  13. import com.hb.proj.data.service.ParamDataService;
  14. import com.hb.proj.model.GatherDataPO;
  15. import com.hb.proj.model.MultiGatherPO;
  16. import com.hb.proj.model.WellParamPO;
  17. import com.hb.proj.model.WellVO;
  18. import com.hb.proj.utils.RespVO;
  19. import com.hb.proj.utils.RespVOBuilder;
  20. import com.hb.xframework.util.DateUtil;
  21. import com.hb.xframework.util.MapUtils;
  22. import jakarta.validation.constraints.NotBlank;
  23. @RestController
  24. @RequestMapping("/diagram")
  25. @Validated
  26. public class DiagramDataController {
  27. @Autowired
  28. private WellService wellService;
  29. @Autowired
  30. private WellParamService wpService;
  31. @Autowired
  32. private DiagramDataService diagramService;
  33. @Autowired
  34. private ParamDataService paramDataService;
  35. /**
  36. * 获得功图绘制数据
  37. * @param wellId
  38. * @param paramCode
  39. * @param action
  40. * @param refTime
  41. * @return
  42. */
  43. @RequestMapping("/getDrawData")
  44. public RespVO<Object> getDrawData(@NotBlank(message = "缺少井记录号") String wellId,
  45. @NotBlank(message = "缺少采集参数编码") String paramCode,String action ,Date refTime){
  46. WellParamPO wparam=wpService.get(wellId, paramCode);
  47. if(wparam==null) {
  48. return RespVOBuilder.error("无数据");
  49. }
  50. MultiGatherPO diagram=diagramService.get(wparam.getParamId(), refTime, action);
  51. if(diagram==null) {
  52. return RespVOBuilder.error("无数据");
  53. }
  54. GatherDataUtils.convert(wparam,diagram);
  55. WellVO well=wellService.get(wellId);
  56. WellParamPO freqParam=wpService.get(wellId, SortCodeConstant.PARAM_FREQ);
  57. GatherDataPO freqPO=paramDataService.getRefFreq(freqParam.getParamId(), diagram.getGatherTime());
  58. GatherDataUtils.convert(freqParam, freqPO);
  59. String freqDesc=freqPO!=null?(freqPO.getDispDataVal()+freqParam.getDisplayUnit()):"";
  60. return RespVOBuilder.ok(buildData(well,wparam,diagram,freqDesc));
  61. }
  62. private Map<String,Object> buildData(WellVO well,WellParamPO wparam,MultiGatherPO diagram,String freq){
  63. String smpTime=DateUtil.format(diagram.getGatherTime(),"yyyy-MM-dd HH:mm:ss");
  64. String[] dtstr=smpTime.split(" ");
  65. Map<String,Object> base=new HashMap<String,Object>();
  66. base.put("xTitle", wparam.getSerialName2()+"("+wparam.getDisplayUnit2()+")");
  67. base.put("yTitle", wparam.getSerialName()+"("+wparam.getDisplayUnit()+")");
  68. base.put("xUnit", wparam.getDisplayUnit2());
  69. base.put("yUnit", wparam.getDisplayUnit());
  70. base.put("title", "时间: "+dtstr[1]);
  71. base.put("type", SortCodeConstant.paramType.get(wparam.getParamCode()));
  72. String[] descTxt= {"隶属单位:"+well.getBelongOrgName(),"井名:"+well.getWellName(),"测试日期:"+dtstr[0],"冲次:"+freq};
  73. Map<String,Object> serial=new HashMap<String,Object>();
  74. serial.put("xvals", diagram.getSerial1());
  75. serial.put("yvals", diagram.getSerial2());
  76. return MapUtils.build("base",base,"serial",serial,"descTxt",descTxt);
  77. }
  78. /*
  79. private Map<String,Object> buildData(){
  80. String nowstr=DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss");
  81. Map<String,Object> base=MapUtils.build("xTitle","位移(m)","yTitle","负荷(kN)","xUnit","m","yUnit","kN","title","CQ-2 2019-09-09","type","GT");
  82. Map<String,Object> serial=MapUtils.build("smpTime",nowstr);
  83. double[] x= {0.2,1.0,2.0,3.0,4.0,5.0,3.0,2.0,1.0};
  84. double[] y= {15.4,28,34,44,50,18,38,66,32};
  85. serial.put("xvals", x);
  86. serial.put("yvals", y);
  87. String[] dtstr=nowstr.split(" ");
  88. String[] descTxt= {"时间: "+dtstr[1],"隶属单位:特油组","井名:杜84","测试日期:"+dtstr[0],"冲次:"};
  89. return MapUtils.build("base",base,"serial",serial,"descTxt",descTxt);
  90. }*/
  91. }