|
@@ -5,16 +5,22 @@ import com.gyee.frame.common.conf.ThreadPoolTaskConfig;
|
|
import com.gyee.frame.common.exception.QiNiuException;
|
|
import com.gyee.frame.common.exception.QiNiuException;
|
|
import com.gyee.frame.common.exception.enums.QiNiuErrorEnum;
|
|
import com.gyee.frame.common.exception.enums.QiNiuErrorEnum;
|
|
import com.gyee.frame.common.feign.RemoteServiceBuilder;
|
|
import com.gyee.frame.common.feign.RemoteServiceBuilder;
|
|
|
|
+import com.gyee.frame.model.auto.Windpowerstation;
|
|
|
|
+import com.gyee.frame.model.auto.WindpowerstationExample;
|
|
import com.gyee.frame.model.custom.export.TsPointData;
|
|
import com.gyee.frame.model.custom.export.TsPointData;
|
|
import com.gyee.frame.service.AnalysissubtablebottomService;
|
|
import com.gyee.frame.service.AnalysissubtablebottomService;
|
|
import com.gyee.frame.service.WindTurbineTestingPointAiService;
|
|
import com.gyee.frame.service.WindTurbineTestingPointAiService;
|
|
|
|
+import com.gyee.frame.service.WindpowerstationService;
|
|
import com.gyee.frame.service.WindturbineService;
|
|
import com.gyee.frame.service.WindturbineService;
|
|
import com.gyee.frame.util.DateUtils;
|
|
import com.gyee.frame.util.DateUtils;
|
|
|
|
+import com.gyee.frame.util.excel.ExcelExportUtils;
|
|
|
|
+import com.gyee.frame.util.excel.FileUtils;
|
|
import com.gyee.frame.util.task.TaskTemplateCallable;
|
|
import com.gyee.frame.util.task.TaskTemplateCallable;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
|
import java.text.DateFormat;
|
|
import java.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -27,25 +33,32 @@ import java.util.stream.Collectors;
|
|
public class GoldenService {
|
|
public class GoldenService {
|
|
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
|
+ @Autowired
|
|
private ExportConfig exportConfig;
|
|
private ExportConfig exportConfig;
|
|
- @Resource
|
|
|
|
|
|
+ @Autowired
|
|
private ThreadPoolTaskConfig taskConfig;
|
|
private ThreadPoolTaskConfig taskConfig;
|
|
- @Resource
|
|
|
|
|
|
+ @Autowired
|
|
private RemoteServiceBuilder remoteService;
|
|
private RemoteServiceBuilder remoteService;
|
|
- @Resource
|
|
|
|
|
|
+ @Autowired
|
|
private WindturbineService windturbineService;
|
|
private WindturbineService windturbineService;
|
|
- @Resource
|
|
|
|
|
|
+ @Autowired
|
|
private WindTurbineTestingPointAiService windService;
|
|
private WindTurbineTestingPointAiService windService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private WindpowerstationService windpowerstationService;
|
|
|
|
|
|
- @Resource
|
|
|
|
|
|
+ @Autowired
|
|
private AnalysissubtablebottomService analysissubtablebottomService;
|
|
private AnalysissubtablebottomService analysissubtablebottomService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FileUtils fileService;
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 一天的时间戳
|
|
* 一天的时间戳
|
|
*/
|
|
*/
|
|
public static final Integer TIMES_TAMP_DAY = 86400;
|
|
public static final Integer TIMES_TAMP_DAY = 86400;
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据场站和风机ID查询
|
|
* 根据场站和风机ID查询
|
|
*
|
|
*
|
|
@@ -80,15 +93,45 @@ public class GoldenService {
|
|
public Map<String, List<Object>> getHistoryDataAll(String station, int templateId, long startTs, long endTs, int interval) {
|
|
public Map<String, List<Object>> getHistoryDataAll(String station, int templateId, long startTs, long endTs, int interval) {
|
|
switch (templateId) {
|
|
switch (templateId) {
|
|
case 1:
|
|
case 1:
|
|
- return getTemplateHistory1(station, startTs, endTs, interval);
|
|
|
|
|
|
+ getTemplateHistory1(station, null,startTs, endTs, interval);
|
|
|
|
+ return null;
|
|
case 2:
|
|
case 2:
|
|
- return getTemplateHistory2(station, startTs, endTs, interval);
|
|
|
|
|
|
+ return getTemplateHistory2(station,null, startTs, endTs, interval);
|
|
default:
|
|
default:
|
|
throw new QiNiuException(QiNiuErrorEnum.TEMPLATE_NO_SUPPORT);
|
|
throw new QiNiuException(QiNiuErrorEnum.TEMPLATE_NO_SUPPORT);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Scheduled(cron = "0 0 1 * * ?")
|
|
|
|
+// @Scheduled(cron = "0/5 * * * * *")
|
|
|
|
+ public void getHistoryData() {
|
|
|
|
+
|
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
|
+ c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)-1,0, 0, 0);
|
|
|
|
+ long beginOfDate = c.getTime().getTime();
|
|
|
|
+ c = Calendar.getInstance();
|
|
|
|
+ c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH),0, 0, 0);
|
|
|
|
+ long endOfDate = c.getTime().getTime();
|
|
|
|
+
|
|
|
|
+ List<Integer> val = exportConfig.getExportval();
|
|
|
|
+ WindpowerstationExample example = new WindpowerstationExample();
|
|
|
|
+ example.createCriteria().andIdLike("%_FDC%");
|
|
|
|
+ List<Windpowerstation> lists = windpowerstationService.selectByExample(example);
|
|
|
|
+ beginOfDate = 1633017600000L;
|
|
|
|
+ endOfDate = 1635696000000L;
|
|
|
|
+ for(int i :val){
|
|
|
|
+ for (Windpowerstation station: lists) {
|
|
|
|
+ getTemplateHistory1(station.getCode(),station.getAddress(),beginOfDate,endOfDate,i*60);
|
|
|
|
+ getTemplateHistory2(station.getCode(),station.getAddress(),beginOfDate,endOfDate,i*60);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 模板1 场站所有风机数据
|
|
* 模板1 场站所有风机数据
|
|
*
|
|
*
|
|
@@ -98,37 +141,38 @@ public class GoldenService {
|
|
* @param interval
|
|
* @param interval
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private Map<String, List<Object>> getTemplateHistory1(String station, long startTs, long endTs, int interval) {
|
|
|
|
- // 风机ID、数据
|
|
|
|
- Map<String, List<Object>> map = new LinkedHashMap<>();
|
|
|
|
|
|
+ private Map<String, Map<String, List<Object>>> getTemplateHistory1(String station, String address,long startTs, long endTs, int interval) {
|
|
|
|
|
|
|
|
+ String val = Integer.valueOf(interval / 60) + "";
|
|
|
|
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ String startTss = dateFormat.format(startTs);
|
|
|
|
+ // 风机ID、数据
|
|
|
|
+ Map<String, Map<String, List<Object>>> map = new LinkedHashMap<>();
|
|
try {
|
|
try {
|
|
List<String> winds = windturbineService.findWindTurbineAll(station);
|
|
List<String> winds = windturbineService.findWindTurbineAll(station);
|
|
if (winds == null)
|
|
if (winds == null)
|
|
- return map;
|
|
|
|
-
|
|
|
|
|
|
+ return null;
|
|
// 异步返回结果
|
|
// 异步返回结果
|
|
- List<Future<Map<String, List<Object>>>> list = new LinkedList<>();
|
|
|
|
|
|
+ List<Future<Map<String, Map<String, List<Object>>>>> list = new LinkedList<>();
|
|
for (String wind : winds) {
|
|
for (String wind : winds) {
|
|
TaskTemplateCallable task = new TaskTemplateCallable(windService, remoteService.ShardingService(),
|
|
TaskTemplateCallable task = new TaskTemplateCallable(windService, remoteService.ShardingService(),
|
|
exportConfig.getTemplate1(), station, wind, startTs, endTs, interval);
|
|
exportConfig.getTemplate1(), station, wind, startTs, endTs, interval);
|
|
Future submit = taskConfig.getExecutor().submit(task);
|
|
Future submit = taskConfig.getExecutor().submit(task);
|
|
list.add(submit);
|
|
list.add(submit);
|
|
}
|
|
}
|
|
-
|
|
|
|
// 返回结果处理
|
|
// 返回结果处理
|
|
- for (Future<Map<String, List<Object>>> future : list) {
|
|
|
|
- Map<String, List<Object>> wtMap = future.get();
|
|
|
|
- for (Map.Entry<String, List<Object>> entry : wtMap.entrySet()) {
|
|
|
|
|
|
+ for (Future<Map<String, Map<String, List<Object>>>> future : list) {
|
|
|
|
+ Map<String, Map<String, List<Object>>> wtMap = future.get();
|
|
|
|
+ for (Map.Entry<String, Map<String, List<Object>>> entry : wtMap.entrySet()) {
|
|
map.put(entry.getKey(), entry.getValue());
|
|
map.put(entry.getKey(), entry.getValue());
|
|
|
|
+ List<String> title = exportConfig.getTemplate1title();
|
|
|
|
+ ExcelExportUtils.exelcExportTem(entry.getValue(), entry.getKey(), title, exportConfig.getExportpath() + "\\excel\\" + startTss.substring(0, 7) + "\\" + val + "\\" + address + "单机\\", entry.getKey());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error(e.getMessage());
|
|
|
|
|
|
+ log.error("error", e);
|
|
throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
|
|
throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
|
|
}
|
|
}
|
|
-
|
|
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -197,27 +241,28 @@ public class GoldenService {
|
|
* @param endTs
|
|
* @param endTs
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private Map<String, List<Object>> getTemplateHistory2(String station, long startTs, long endTs, int interval) {
|
|
|
|
|
|
+ private Map<String, List<Object>> getTemplateHistory2(String station,String address, long startTs, long endTs, int interval) {
|
|
|
|
+
|
|
|
|
+ String val = Integer.valueOf(interval / 60) + "";
|
|
// 风机ID、数据
|
|
// 风机ID、数据
|
|
Map<String, List<Object>> map = new LinkedHashMap<>();
|
|
Map<String, List<Object>> map = new LinkedHashMap<>();
|
|
-
|
|
|
|
try {
|
|
try {
|
|
|
|
+
|
|
// 上网电量
|
|
// 上网电量
|
|
String point = exportConfig.getTemplate2swdl().get(station);
|
|
String point = exportConfig.getTemplate2swdl().get(station);
|
|
String[] points = point.split(",");
|
|
String[] points = point.split(",");
|
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
String startTss = dateFormat.format(startTs);
|
|
String startTss = dateFormat.format(startTs);
|
|
String endTss = dateFormat.format(endTs);
|
|
String endTss = dateFormat.format(endTs);
|
|
- List<Map> data = analysissubtablebottomService.selectByRecorddateGrop(startTss,endTss,station,points);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //List<TsPointData> data = remoteService.ShardingService().getHistorySnap(point, startTs, endTs, TIMES_TAMP_DAY);
|
|
|
|
|
|
+ List<Map> data = analysissubtablebottomService.selectByRecorddateGrop(startTss, endTss, station, points);
|
|
List<Object> list = new ArrayList<>();
|
|
List<Object> list = new ArrayList<>();
|
|
- //list.add(data.stream().map(p -> DateUtils.format(p.getTs(), DateUtils.DATE_PATTERN)).collect(Collectors.toList()));
|
|
|
|
- //list.add(data.stream().map(TsPointData::getDoubleValue).collect(Collectors.toList()));
|
|
|
|
-
|
|
|
|
list.add(data.stream().map(p -> dateFormat.format(p.get("RECORDDATE"))).collect(Collectors.toList()));
|
|
list.add(data.stream().map(p -> dateFormat.format(p.get("RECORDDATE"))).collect(Collectors.toList()));
|
|
list.add(data.stream().map(p -> Double.valueOf(p.get("SWDL").toString())).collect(Collectors.toList()));
|
|
list.add(data.stream().map(p -> Double.valueOf(p.get("SWDL").toString())).collect(Collectors.toList()));
|
|
|
|
+ List<String> swdltitle = exportConfig.getTemplate2swdltitle();
|
|
|
|
+ Map<String, List<Object>> swdlVos = new HashMap<>();
|
|
|
|
+ swdlVos.put("F1", data.stream().map(p -> dateFormat.format(p.get("RECORDDATE"))).collect(Collectors.toList()));
|
|
|
|
+ swdlVos.put("F2", data.stream().map(p -> Double.valueOf(p.get("SWDL").toString())).collect(Collectors.toList()));
|
|
|
|
+ ExcelExportUtils.exelcExportTem(swdlVos, "日上网电量", swdltitle, exportConfig.getExportpath() + "\\excel\\" + startTss.substring(0, 7) + "//" + val + "//", address+"测风塔");
|
|
map.put("swdl", list);
|
|
map.put("swdl", list);
|
|
|
|
|
|
// 上网功率
|
|
// 上网功率
|
|
@@ -226,18 +271,22 @@ public class GoldenService {
|
|
List<Object> list2 = new ArrayList<>();
|
|
List<Object> list2 = new ArrayList<>();
|
|
list2.add(data2.stream().map(p -> DateUtils.format(p.getTs(), DateUtils.DATE_TIME_PATTERN)).collect(Collectors.toList()));
|
|
list2.add(data2.stream().map(p -> DateUtils.format(p.getTs(), DateUtils.DATE_TIME_PATTERN)).collect(Collectors.toList()));
|
|
list2.add(data2.stream().map(TsPointData::getDoubleValue).collect(Collectors.toList()));
|
|
list2.add(data2.stream().map(TsPointData::getDoubleValue).collect(Collectors.toList()));
|
|
|
|
+ Map<String, List<Object>> swglVos = new HashMap<>();
|
|
|
|
+ swglVos.put("F1", data2.stream().map(p -> DateUtils.format(p.getTs(), DateUtils.DATE_TIME_PATTERN)).collect(Collectors.toList()));
|
|
|
|
+ swglVos.put("F2", data2.stream().map(TsPointData::getDoubleValue).collect(Collectors.toList()));
|
|
|
|
+ List<String> swgltitle = exportConfig.getTemplate2swgltitle();
|
|
|
|
+ ExcelExportUtils.exelcExportTem(swglVos, "上网功率", swgltitle, exportConfig.getExportpath() + "\\excel\\" + startTss.substring(0, 7) + "//" + val + "//", address+"测风塔");
|
|
map.put("swgl", list2);
|
|
map.put("swgl", list2);
|
|
|
|
|
|
// 测风塔数据
|
|
// 测风塔数据
|
|
String point3 = exportConfig.getTemplate2cft().get(station);
|
|
String point3 = exportConfig.getTemplate2cft().get(station);
|
|
- List<Object> maps = getTemplateHistory2(startTs, endTs, interval, point3);
|
|
|
|
- map.put("cft", maps);
|
|
|
|
-
|
|
|
|
- } catch (QiNiuException e) {
|
|
|
|
- log.error(e.getMessage());
|
|
|
|
|
|
+ Map<String, List<Object>> cftlVos = getTemplateHistory2(startTs, endTs, interval, point3);
|
|
|
|
+ List<String> cftltitle = exportConfig.getTemplate2cfttitle();
|
|
|
|
+ ExcelExportUtils.exelcExportTem(cftlVos, "测风塔数据", cftltitle, exportConfig.getExportpath() + "\\excel\\" + startTss.substring(0, 7) + "//" + val + "//", address+"测风塔");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("error", e);
|
|
throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
|
|
throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
|
|
}
|
|
}
|
|
-
|
|
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -251,15 +300,20 @@ public class GoldenService {
|
|
* @param points
|
|
* @param points
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private List<Object> getTemplateHistory2(long startTs, long endTs, int interval, String points) {
|
|
|
|
|
|
+ private Map<String, List<Object>> getTemplateHistory2(long startTs, long endTs, int interval, String points) {
|
|
List<Object> list = new ArrayList<>();
|
|
List<Object> list = new ArrayList<>();
|
|
|
|
|
|
|
|
+ Map<String, List<Object>> map = new HashMap<>();
|
|
|
|
+
|
|
|
|
+
|
|
// 第一列添加时间
|
|
// 第一列添加时间
|
|
- List<String> intervals = dateInterval(startTs, endTs, interval);
|
|
|
|
|
|
+ List<Object> intervals = dateInterval(startTs, endTs, interval);
|
|
list.add(intervals);
|
|
list.add(intervals);
|
|
|
|
+ map.put("F1", intervals);
|
|
|
|
|
|
try {
|
|
try {
|
|
String[] splits = points.split(",");
|
|
String[] splits = points.split(",");
|
|
|
|
+ int num = 2;
|
|
for (String point : splits) {
|
|
for (String point : splits) {
|
|
List<TsPointData> data = remoteService.ShardingService().getHistorySnap(point, startTs, endTs, interval);
|
|
List<TsPointData> data = remoteService.ShardingService().getHistorySnap(point, startTs, endTs, interval);
|
|
|
|
|
|
@@ -271,6 +325,8 @@ public class GoldenService {
|
|
collect = data.stream().map(TsPointData::getDoubleValue).collect(Collectors.toList());
|
|
collect = data.stream().map(TsPointData::getDoubleValue).collect(Collectors.toList());
|
|
}
|
|
}
|
|
list.add(collect);
|
|
list.add(collect);
|
|
|
|
+ map.put("F" + num, collect);
|
|
|
|
+ num++;
|
|
}
|
|
}
|
|
|
|
|
|
} catch (QiNiuException e) {
|
|
} catch (QiNiuException e) {
|
|
@@ -278,7 +334,7 @@ public class GoldenService {
|
|
throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
|
|
throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
|
|
}
|
|
}
|
|
|
|
|
|
- return list;
|
|
|
|
|
|
+ return map;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -290,8 +346,8 @@ public class GoldenService {
|
|
* @param interval
|
|
* @param interval
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private List<String> dateInterval(long st, long et, int interval) {
|
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
|
|
|
+ private List<Object> dateInterval(long st, long et, int interval) {
|
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
int val = interval * 1000;
|
|
int val = interval * 1000;
|
|
while (st < et) {
|
|
while (st < et) {
|
|
list.add(DateUtils.format(st, DateUtils.DATE_TIME_PATTERN));
|
|
list.add(DateUtils.format(st, DateUtils.DATE_TIME_PATTERN));
|