Browse Source

设备运行查询-表格展示接口

sl 2 months ago
parent
commit
396a39dc77

+ 14 - 2
module_tpm/src/main/java/org/jeecg/modules/equipmentOnoff/controller/EquipmentOnoffController.java

@@ -191,15 +191,27 @@ public class EquipmentOnoffController extends JeecgController<EquipmentOnoff, IE
 	 }
 
 	 /**
-	  * 设备健康-设备运行查询  从mongodb查询设备的历史数据  查询给的日期当天所有的数据
+	  * 设备健康-设备运行查询-折线展示  从mongodb查询设备的历史数据  查询给的日期当天所有的数据
 	  *
 	  * @return
 	  */
 	 //@AutoLog(value = "设备健康-设备运行查询")
-	 @ApiOperation(value="设备健康-设备运行查询", notes="设备健康-设备运行查询")
+	 @ApiOperation(value="设备健康-设备运行查询-折线展示", notes="设备健康-设备运行查询-折线展示")
 	 @GetMapping(value = "/getEquipmentHistoryData")
 	 public Result<List<Map<String, Object>>> getEquipmentHistoryData(HistoryParamDayDto historyParamDayDto) {
 		 return equipmentOnoffService.getEquipmentHistoryData(historyParamDayDto);
 	 }
 
+	 /**
+	  * 设备健康-设备运行查询-表格展示  从mongodb查询设备的历史数据  查询给的日期当天所有的数据
+	  *
+	  * @return
+	  */
+	 //@AutoLog(value = "设备健康-设备运行查询")
+	 @ApiOperation(value="设备健康-设备运行查询-表格展示", notes="设备健康-设备运行查询-表格展示")
+	 @GetMapping(value = "/getEquipHistoryDataList")
+	 public Result<List<Map<String, Object>>> getEquipHistoryDataList(HistoryParamDayDto historyParamDayDto) {
+		 return equipmentOnoffService.getEquipHistoryDataList(historyParamDayDto);
+	 }
+
 }

+ 2 - 0
module_tpm/src/main/java/org/jeecg/modules/equipmentOnoff/service/IEquipmentOnoffService.java

@@ -21,4 +21,6 @@ public interface IEquipmentOnoffService extends IService<EquipmentOnoff> {
 
     Result<List<Map<String, Object>>> getEquipmentHistoryData(HistoryParamDayDto historyParamDayDto);
 
+    Result<List<Map<String, Object>>> getEquipHistoryDataList(HistoryParamDayDto historyParamDayDto);
+
 }

+ 80 - 0
module_tpm/src/main/java/org/jeecg/modules/equipmentOnoff/service/impl/EquipmentOnoffServiceImpl.java

@@ -9,6 +9,8 @@ import org.jeecg.modules.equipmentOnoff.entity.HistoryParamDto;
 import org.jeecg.modules.equipmentOnoff.mapper.EquipmentOnoffMapper;
 import org.jeecg.modules.equipmentOnoff.service.IEquipmentOnoffService;
 import org.jeecg.modules.tpmEquipment.service.ITpmEquipmentService;
+import org.jeecg.modules.tpmparams.entity.TpmParams;
+import org.jeecg.modules.tpmparams.mapper.TpmParamsMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.data.mongodb.core.query.Criteria;
@@ -37,6 +39,10 @@ public class EquipmentOnoffServiceImpl extends ServiceImpl<EquipmentOnoffMapper,
     @SuppressWarnings("all")
     private ITpmEquipmentService tpmEquipmentService;
 
+    @Autowired
+    @SuppressWarnings("all")
+    private TpmParamsMapper tpmParamsMapper;
+
     public Map<String, Date> splitByMonth(Date beginTime, Date endTime){
         Map<String, Date> dateMap = new HashMap<>();
         Calendar calB = Calendar.getInstance();
@@ -105,6 +111,7 @@ public class EquipmentOnoffServiceImpl extends ServiceImpl<EquipmentOnoffMapper,
         return Result.ok(historyList);
     }
 
+    //折线展示
     @Override
     public Result<List<Map<String, Object>>> getEquipmentHistoryData(HistoryParamDayDto historyParamDayDto){
         List<Map<String, Object>> historyList = new ArrayList<>();
@@ -168,4 +175,77 @@ public class EquipmentOnoffServiceImpl extends ServiceImpl<EquipmentOnoffMapper,
         return Result.ok(historyList);
     }
 
+    //表格展示
+    public Result<List<Map<String, Object>>> getEquipHistoryDataList(HistoryParamDayDto historyParamDayDto){
+        List<Map<String, Object>> historyList = new ArrayList<>();
+        List<Collectdata> orgDataList = new ArrayList<>();
+        //根据设备id找到设备编号
+        String equipmentcode;
+        try {
+            equipmentcode = (tpmEquipmentService.getById(historyParamDayDto.getEquipmentid())).getEquipmentcode();
+        }catch (NullPointerException e){
+            return Result.error("id为" + historyParamDayDto.getEquipmentid() + "的设备找不到设备编号,无法进行数据查询!");
+        }
+        List<TpmParams> tpmParamsList = tpmParamsMapper.queryByEquipId(historyParamDayDto.getEquipmentid());
+        if(tpmParamsList.size()==0) {
+            return Result.error("未找到对应数据");
+        }
+        //根据时间确定要查询哪一天的数据
+        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+        sdf1.setTimeZone(TimeZone.getTimeZone("UTC")); // 设置时区为UTC
+        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
+//        String dateStr = historyParamDayDto.getDate();
+        Date date;
+        String dateStr = historyParamDayDto.getDate().replace("\"", "");
+        try {
+            if(dateStr.contains("T")){
+                date = sdf1.parse(dateStr);
+            }else{
+                date = sdf2.parse(dateStr);
+            }
+
+        } catch (ParseException e) {
+            return Result.error("日期类型转换失败!");
+        }
+
+        Calendar dateCal = Calendar.getInstance();
+        dateCal.setTime(date);
+        dateCal.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+        Date startDate = dateCal.getTime();
+        // 将日期增加一天
+        dateCal.add(Calendar.DATE, 1);
+        Date endDate = dateCal.getTime();
+        System.out.println(new SimpleDateFormat("yyyyMM").format(startDate));
+        System.out.println(new SimpleDateFormat("yyyyMM").format(endDate));
+        //创建查询对象
+        Query HistoryQuery = new Query();
+        //添加查询条件
+        HistoryQuery.addCriteria(Criteria.where("equipmentcode").is(equipmentcode));
+//        HistoryQuery.addCriteria(Criteria.where("logtime").is(dateCal.getTime())); // 大于等于startDate且小于等于endDate
+        HistoryQuery.addCriteria(Criteria.where("logtime").gte(startDate).lte(endDate)); // 大于等于startDate且小于等于endDate
+
+        //执行查询
+        try{
+            orgDataList.addAll(mongoTemplate.find(HistoryQuery, Collectdata.class, "data_"+new SimpleDateFormat("yyyyMM").format(startDate)));
+        }catch (NullPointerException e){}
+        //表格展示示例:
+        //[{"tagname":"电流","logtime","2025-02-24 10:10:10","tagvalue":12},.......................]
+        for(Collectdata collectdata:orgDataList){
+            Map<String, Object> dataMap = new ObjectMapper().convertValue(collectdata.getProperties(), Map.class);
+            for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
+                for(TpmParams tpmParams:tpmParamsList){
+                    if(tpmParams.getSymbol().equals(entry.getKey())){
+                        Map<String, Object> dataMapNew = new HashMap<>();
+                        dataMapNew.put("tagname", tpmParams.getTagname());//参数名称
+                        dataMapNew.put("logtime", collectdata.getLogtime());//记录时间
+                        dataMapNew.put("tagvalue", entry.getValue());//参数值
+                        historyList.add(dataMapNew);
+                    }
+                }
+            }
+        }
+        return Result.ok(historyList);
+
+    }
+
 }