|
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.modules.collectdata.entity.Collectdata;
|
|
|
import org.jeecg.modules.equipmentOnoff.entity.EquipmentOnoff;
|
|
|
+import org.jeecg.modules.equipmentOnoff.entity.HistoryParamDayDto;
|
|
|
import org.jeecg.modules.equipmentOnoff.entity.HistoryParamDto;
|
|
|
import org.jeecg.modules.equipmentOnoff.mapper.EquipmentOnoffMapper;
|
|
|
import org.jeecg.modules.equipmentOnoff.service.IEquipmentOnoffService;
|
|
@@ -16,6 +17,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -69,7 +71,7 @@ public class EquipmentOnoffServiceImpl extends ServiceImpl<EquipmentOnoffMapper,
|
|
|
return dateMap;
|
|
|
}
|
|
|
|
|
|
- public Result<List<Map<String, Object>>> getEquipmentHistoryData(HistoryParamDto historyParamDto){
|
|
|
+ public Result<List<Map<String, Object>>> getEquipmentHistoryData1(HistoryParamDto historyParamDto){
|
|
|
List<Map<String, Object>> historyList = new ArrayList<>();
|
|
|
List<Collectdata> orgDataList = new ArrayList<>();
|
|
|
//根据设备id找到设备编号
|
|
@@ -102,4 +104,54 @@ public class EquipmentOnoffServiceImpl extends ServiceImpl<EquipmentOnoffMapper,
|
|
|
return Result.ok(historyList);
|
|
|
}
|
|
|
|
|
|
+ public Result<List<Map<String, Object>>> getEquipmentHistoryData(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() + "的设备找不到设备编号,无法进行数据查询!");
|
|
|
+ }
|
|
|
+ //根据时间确定要查询哪一天的数据
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
|
|
+ sdf.setTimeZone(TimeZone.getTimeZone("UTC")); // 设置时区为UTC
|
|
|
+// String dateStr = historyParamDayDto.getDate();
|
|
|
+ Date date;
|
|
|
+ String dateStr = historyParamDayDto.getDate().replace("\"", "");
|
|
|
+ try {
|
|
|
+ date = sdf.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){}
|
|
|
+ for(Collectdata collectdata:orgDataList){
|
|
|
+ Map<String, Object> dataMap = new ObjectMapper().convertValue(collectdata.getProperties(), Map.class);
|
|
|
+ dataMap.put("logtime", collectdata.getLogtime());
|
|
|
+ historyList.add(dataMap);
|
|
|
+ }
|
|
|
+ return Result.ok(historyList);
|
|
|
+ }
|
|
|
+
|
|
|
}
|