|
@@ -1,20 +1,32 @@
|
|
package com.cpp.web.controller.stationDataQuery;
|
|
package com.cpp.web.controller.stationDataQuery;
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.cpp.common.core.domain.R;
|
|
import com.cpp.common.core.domain.R;
|
|
-import com.cpp.web.domain.station.InverterStatusData;
|
|
|
|
|
|
+import com.cpp.web.domain.station.*;
|
|
|
|
+import com.cpp.web.service.station.ElectricFieldService;
|
|
|
|
+import com.cpp.web.service.station.InverterInfoService;
|
|
import com.cpp.web.service.station.InverterStatusDataService;
|
|
import com.cpp.web.service.station.InverterStatusDataService;
|
|
|
|
+import com.cpp.web.service.station.WindTurbineInfoService;
|
|
|
|
+import com.cpp.web.utils.DownloadFileUrlCodeUtil;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -27,9 +39,12 @@ import java.util.Date;
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
@RequestMapping("/inverterstatusdata")
|
|
@RequestMapping("/inverterstatusdata")
|
|
@Api(value = "inverterstatusdata", tags = "idp_inverter_status_data管理")
|
|
@Api(value = "inverterstatusdata", tags = "idp_inverter_status_data管理")
|
|
|
|
+@Slf4j
|
|
public class InverterStatusDataController {
|
|
public class InverterStatusDataController {
|
|
|
|
|
|
private final InverterStatusDataService inverterStatusDataService;
|
|
private final InverterStatusDataService inverterStatusDataService;
|
|
|
|
+ private final ElectricFieldService electricFieldService;
|
|
|
|
+ private final InverterInfoService inverterInfoService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 分页查询
|
|
* 分页查询
|
|
@@ -63,4 +78,109 @@ public class InverterStatusDataController {
|
|
page.setMaxLimit((long) -1);
|
|
page.setMaxLimit((long) -1);
|
|
return R.ok(inverterStatusDataService.page(page, inverterStatusDataService.getByStationCodeAndEquipmentIdAndTimeBetween(stationCode, equipmentId, new Date(startTime), new Date(endTime))));
|
|
return R.ok(inverterStatusDataService.page(page, inverterStatusDataService.getByStationCodeAndEquipmentIdAndTimeBetween(stationCode, equipmentId, new Date(startTime), new Date(endTime))));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @GetMapping("/export")
|
|
|
|
+ public void export(String stationCode, String equipmentId, Long startTime, Long endTime, HttpServletResponse response){
|
|
|
|
+ BufferedOutputStream bos = null;
|
|
|
|
+ try {
|
|
|
|
+ ElectricField electricField = electricFieldService.findByStationCode(stationCode);
|
|
|
|
+ List<InverterInfo> inverterInfoList = inverterInfoService.findByStationCode(stationCode);
|
|
|
|
+ List<InverterStatusData> list = inverterStatusDataService.list(inverterStatusDataService.getByStationCodeAndEquipmentIdAndTimeBetween(stationCode, equipmentId, new Date(startTime), new Date(endTime)));
|
|
|
|
+ StringBuilder templateContent = new StringBuilder();
|
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
|
+
|
|
|
|
+ List<String> tableColumns = new ArrayList<>();
|
|
|
|
+ tableColumns.add("所属场站");
|
|
|
|
+ tableColumns.add("设备名称");
|
|
|
|
+ tableColumns.add("时间");
|
|
|
|
+ tableColumns.add("状态");
|
|
|
|
+ tableColumns.add("有功(KW)");
|
|
|
|
+ tableColumns.add("无功(KVar)");
|
|
|
|
+ tableColumns.add("电压(V)");
|
|
|
|
+ tableColumns.add("电流(A)");
|
|
|
|
+ tableColumns.add("当日发电量(kW·h)");
|
|
|
|
+ tableColumns.add("累积发电量(MW·h)");
|
|
|
|
+ tableColumns.add("当日并网小时数");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String header = "";
|
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
|
+
|
|
|
|
+ for (String tableColumn : tableColumns) {
|
|
|
|
+ header += "\"" + tableColumn + "\",";
|
|
|
|
+ }
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ // 设备名称集合
|
|
|
|
+ Set<String> nameList = new TreeSet<>();
|
|
|
|
+ if (!list.isEmpty()){
|
|
|
|
+ list.sort(Comparator.comparing(InverterStatusData::getEquipmentId).thenComparing(InverterStatusData::getTime));
|
|
|
|
+ }
|
|
|
|
+ for (InverterStatusData inverterStatusData : list) {
|
|
|
|
+ content.append(electricField.getName() + "," );
|
|
|
|
+ Optional<String> name = inverterInfoList.stream()
|
|
|
|
+ .filter(w -> w.getId().longValue()==inverterStatusData.getEquipmentId().longValue())
|
|
|
|
+ .map(InverterInfo::getName)
|
|
|
|
+ .findFirst();
|
|
|
|
+ content.append(name.get() + "," );
|
|
|
|
+ nameList.add(name.get());
|
|
|
|
+ content.append(DateUtil.format(inverterStatusData.getTime(),"yyyy-MM-dd HH:mm") + "," );
|
|
|
|
+ int statusValue = inverterStatusData.getStatus();
|
|
|
|
+ if (statusValue == 1) {
|
|
|
|
+ content.append("运行,");
|
|
|
|
+ } else if (statusValue == 2) {
|
|
|
|
+ content.append("待机,");
|
|
|
|
+ } else if (statusValue == 3) {
|
|
|
|
+ content.append("停用,");
|
|
|
|
+ } else if (statusValue == 4) {
|
|
|
|
+ content.append("故障,");
|
|
|
|
+ }
|
|
|
|
+ content.append(inverterStatusData.getActivePower() + "," );
|
|
|
|
+ content.append(inverterStatusData.getReactivePower() + "," );
|
|
|
|
+ content.append(inverterStatusData.getVoltage() + "," );
|
|
|
|
+ content.append(inverterStatusData.getElectricalCurrent() + "," );
|
|
|
|
+ content.append(inverterStatusData.getDayElectricQuantity() + "," );
|
|
|
|
+ content.append(inverterStatusData.getCumulativeGeneratedEnergy() + "," );
|
|
|
|
+ content.append(inverterStatusData.getDayGridConnectedHours() + "," );
|
|
|
|
+ content.append("\r\n");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ header += "\r\n";
|
|
|
|
+ templateContent.append(header);
|
|
|
|
+
|
|
|
|
+ templateContent.append(content.toString());
|
|
|
|
+
|
|
|
|
+ String fileName = "";
|
|
|
|
+ String fileNameDeviceName = "";
|
|
|
|
+ for (String name : nameList) {
|
|
|
|
+ fileNameDeviceName += name + "_";
|
|
|
|
+ }
|
|
|
|
+ if (sdf.format(startTime).equals(sdf.format(endTime))) {
|
|
|
|
+ fileName = electricField.getName() + sdf.format(startTime) + "[" +fileNameDeviceName.substring(0,fileNameDeviceName.length()-1) + "].csv";
|
|
|
|
+ } else {
|
|
|
|
+ fileName = electricField.getName() + sdf.format(startTime) + "至" + sdf.format(endTime) + "[" +fileNameDeviceName.substring(0,fileNameDeviceName.length()-1) + "].csv";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ response.setContentType("application/x-msdownload;charset=UTF-8");
|
|
|
|
+ response.setHeader("Content-disposition", "attachment; filename=" + DownloadFileUrlCodeUtil.transUrlChinese(fileName));
|
|
|
|
+ byte[] templateContentBytes = templateContent.toString().getBytes("UTF-8");
|
|
|
|
+ bos = new BufferedOutputStream(response.getOutputStream());
|
|
|
|
+ bos.write(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
|
|
|
|
+ bos.write(templateContentBytes);
|
|
|
|
+ response.flushBuffer();
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("系统错误:" + e.getMessage(), e);
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ } finally {
|
|
|
|
+ if (bos != null) {
|
|
|
|
+ try {
|
|
|
|
+ bos.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.error("系统错误:" + e.getMessage(), e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|