|
@@ -1,5 +1,9 @@
|
|
|
package com.example.opc_da.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelWriter;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.example.opc_common.entity.*;
|
|
@@ -19,7 +23,11 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
@@ -203,7 +211,7 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
allItemList = (List<Item>) queryServiceUtil.exchangeData(allItemList);
|
|
|
for (Item item : allItemList) {
|
|
|
String dataValue = item.getDataValue();
|
|
|
- if(Blank.isNotEmpty(dataValue)){
|
|
|
+ if (Blank.isNotEmpty(dataValue)) {
|
|
|
Integer itemId = item.getId();
|
|
|
DataModel dm = dmMap.get(itemId);
|
|
|
if (Blank.isNotEmpty(dm) && dm.getModelType().equals(ConstantStr.VALUE_REPLACE)) {
|
|
@@ -394,6 +402,14 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Result getItemListLastValue(List<Integer> idList) {
|
|
|
+ List<Item> itemList = itemGroupDao.getItemsParentByIdList(idList);
|
|
|
+ //从工具类中组装对应数据项的数据到集合中
|
|
|
+ itemList = (List<Item>) queryServiceUtil.exchangeData(itemList);
|
|
|
+ return Result.ok(itemList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Result getItemListValue(List<Integer> idList, String startTime, String endTime) {
|
|
|
List<Item> itemList = itemGroupDao.getItemsParentByIdList(idList);
|
|
|
//从工具类中组装对应数据项的数据到集合中
|
|
@@ -404,4 +420,48 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
);
|
|
|
return Result.ok(itemList);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportItemListData(List<Integer> idList, String startTime, String endTime, HttpServletResponse response) {
|
|
|
+ List<Item> itemList = itemGroupDao.getItemsParentByIdList(idList);
|
|
|
+ //从工具类中组装对应数据项的数据到集合中
|
|
|
+ itemList = (List<Item>) queryServiceUtil.exchangeDatas(
|
|
|
+ DateUtil.strYmdhmsChangeDate(startTime),
|
|
|
+ DateUtil.strYmdhmsChangeDate(endTime),
|
|
|
+ itemList
|
|
|
+ );
|
|
|
+ List<List<String>> rows = new ArrayList<>();
|
|
|
+ List<String> header = CollUtil.newArrayList("时间", "数据项名称", "值");
|
|
|
+ rows.add(header);
|
|
|
+ if (Blank.isNotEmpty(itemList)) {
|
|
|
+ for (Item item : itemList) {
|
|
|
+ List<String> dataTimeList = item.getDataTimeList();
|
|
|
+ List<String> dataValueList = item.getDataValueList();
|
|
|
+ if (Blank.isNotEmpty(dataTimeList)) {
|
|
|
+ for (int i = 0; i < dataTimeList.size() - 1; i++) {
|
|
|
+ List<String> row = CollUtil.newArrayList(dataTimeList.get(i), item.getItemReadName(), dataValueList.get(i));
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ServletOutputStream out = null;
|
|
|
+ ExcelWriter writer = null;
|
|
|
+ try {
|
|
|
+ writer = ExcelUtil.getWriter(true);
|
|
|
+ writer.write(rows, true);
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(new Date().getTime() + ".xlsx", "UTF-8"));
|
|
|
+ response.setHeader("Access-Control-Expose-Headers", "Content-disposition");
|
|
|
+ out = response.getOutputStream();
|
|
|
+ writer.flush(out, true);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } finally {
|
|
|
+ if (writer != null) {
|
|
|
+ writer.close();
|
|
|
+ }
|
|
|
+ IoUtil.close(out);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|