|
@@ -1,5 +1,7 @@
|
|
|
package org.jeecg.modules.equipmentOnoff.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.modules.collectdata.entity.Collectdata;
|
|
@@ -12,6 +14,8 @@ 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.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
@@ -22,6 +26,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: tpm_equipment_onoff
|
|
@@ -245,7 +250,83 @@ public class EquipmentOnoffServiceImpl extends ServiceImpl<EquipmentOnoffMapper,
|
|
|
}
|
|
|
}
|
|
|
return Result.ok(historyList);
|
|
|
+ }
|
|
|
|
|
|
+ public Result<IPage<Map<String, Object>>> getHistoryListByPage(Integer pageNo, Integer pageSize, HistoryParamDayDto historyParamDayDto){
|
|
|
+ //1.根据设备id查找设备的参数信息列表 找不到直接返回
|
|
|
+ List<TpmParams> tpmParamsList = tpmParamsMapper.queryByEquipId(historyParamDayDto.getEquipmentid());
|
|
|
+ if(tpmParamsList.size()==0) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ //2.根据设备id找到设备编号 找不到直接返回
|
|
|
+ String equipmentcode;
|
|
|
+ try {
|
|
|
+ equipmentcode = (tpmEquipmentService.getById(historyParamDayDto.getEquipmentid())).getEquipmentcode();
|
|
|
+ }catch (NullPointerException e){
|
|
|
+ return Result.error("id为" + historyParamDayDto.getEquipmentid() + "的设备找不到设备编号,无法进行数据查询!");
|
|
|
+ }
|
|
|
+ //3.处理传来的时间数据 根据时间确定要查询哪一天的数据 处理成带时区的时间
|
|
|
+ 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();
|
|
|
+
|
|
|
+ //4.通过前面处理得到的设备code和时间,以及page分页读取mongodb
|
|
|
+ List<Map<String, Object>> historyList = new ArrayList<>();
|
|
|
+ List<Collectdata> orgDataList = new ArrayList<>();
|
|
|
+ //创建查询对象
|
|
|
+ Query HistoryQuery = new Query();
|
|
|
+ //添加查询条件
|
|
|
+ HistoryQuery.addCriteria(Criteria.where("equipmentcode").is(equipmentcode));
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //手动创建一个分页
|
|
|
+ //创建分页示例
|
|
|
+// Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
|
|
|
+ List<Map<String, Object>> pagedRecords = historyList.stream()
|
|
|
+ .skip((long) (pageNo - 1) * pageSize)
|
|
|
+ .limit(pageSize)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ IPage<Map<String, Object>> result = new Page<>(pageNo, pageSize, historyList.size());
|
|
|
+ result.setRecords(pagedRecords);
|
|
|
+ return Result.ok(result);
|
|
|
}
|
|
|
|
|
|
}
|