|
@@ -1,19 +1,29 @@
|
|
|
package com.zcxk.rmcp.web.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import com.zcxk.core.utils.export.EasyExcelUtil;
|
|
|
import com.zcxk.rmcp.api.dto.device.DeviceDataDto;
|
|
|
import com.zcxk.rmcp.api.vo.DeviceDataVo;
|
|
|
+import com.zcxk.rmcp.api.vo.MeasuringPointVo;
|
|
|
+import com.zcxk.rmcp.api.vo.ProductMeasuringDictVo;
|
|
|
+import com.zcxk.rmcp.core.dao.DeviceMapper;
|
|
|
import com.zcxk.rmcp.core.dao.mongo.DeviceDataDao;
|
|
|
+import com.zcxk.rmcp.core.entity.Device;
|
|
|
import com.zcxk.rmcp.core.mongo.DeviceData;
|
|
|
import com.zcxk.rmcp.core.mongo.DeviceDataItem;
|
|
|
import com.zcxk.rmcp.web.service.DeviceDataService;
|
|
|
+import com.zcxk.rmcp.web.service.ProductMeasuringPointService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -26,6 +36,10 @@ public class DeviceDataServiceImpl implements DeviceDataService {
|
|
|
|
|
|
@Resource
|
|
|
private DeviceDataDao deviceDataDao;
|
|
|
+ @Resource
|
|
|
+ private DeviceMapper deviceMapper;
|
|
|
+ @Autowired
|
|
|
+ private ProductMeasuringPointService productMeasuringPointService;
|
|
|
|
|
|
@Override
|
|
|
public List<DeviceDataVo> getData(DeviceDataDto deviceDataDto) {
|
|
@@ -58,4 +72,57 @@ public class DeviceDataServiceImpl implements DeviceDataService {
|
|
|
return deviceDataDao.queryDeviceDataItem(deviceDataDto.getDeviceId(),deviceDataDto.getStartDate(),
|
|
|
deviceDataDto.getEndDate());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getDataExcel(DeviceDataDto deviceDataDto, HttpServletResponse httpServletResponse) {
|
|
|
+ List<DeviceDataItem> list = deviceDataDao.queryDeviceDataItem(deviceDataDto.getDeviceId(),deviceDataDto.getStartDate(),
|
|
|
+ deviceDataDto.getEndDate());
|
|
|
+
|
|
|
+ Device device = deviceMapper.findById(deviceDataDto.getDeviceId());
|
|
|
+ List<MeasuringPointVo> measuringList = productMeasuringPointService.getMeasuringPoint(device.getProductId());
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ List<String> head = getHeadList(measuringList);
|
|
|
+
|
|
|
+ List<List<Object>> dataList = new ArrayList<>();
|
|
|
+ for (DeviceDataItem deviceDataItem : list) {
|
|
|
+ List<Object> item = new ArrayList<>();
|
|
|
+ item.add(DateUtil.format(new Date(deviceDataItem.getReceiveTime()), DatePattern.NORM_DATETIME_PATTERN));
|
|
|
+ for (MeasuringPointVo vo : measuringList) {
|
|
|
+ item.add(getRowsValue(vo,deviceDataItem.getMeasureData()));
|
|
|
+ }
|
|
|
+ dataList.add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ EasyExcelUtil.excelDynamicWrite(httpServletResponse,"历史数据",head,dataList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Object getRowsValue(MeasuringPointVo vo, Map<String, Object> measureData) {
|
|
|
+
|
|
|
+ String value = MapUtil.getStr(measureData,vo.getMeasuringCode());
|
|
|
+ if (value != null) {
|
|
|
+ Optional<ProductMeasuringDictVo> measuringOptional = vo.getDictList().stream().filter(dto -> StringUtils.equals(value,dto.getDataValue())).findFirst();
|
|
|
+ if (measuringOptional.isPresent() && StringUtils.equals("1",vo.getMeasuringDataType())) {
|
|
|
+ return measuringOptional.get().getDataName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getHeadList(List<MeasuringPointVo> measuringList){
|
|
|
+ List<String> head = new ArrayList<>();
|
|
|
+ head.add("上报时间");
|
|
|
+ measuringList.forEach(m -> head.add(m.getMeasuringName()));
|
|
|
+ return head;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|