|
@@ -1,11 +1,16 @@
|
|
|
package com.ruoyi.biz.controller;
|
|
|
|
|
|
-import com.ruoyi.biz.domain.*;
|
|
|
+import com.ruoyi.biz.domain.IndexData;
|
|
|
+import com.ruoyi.biz.domain.TwinCalc2hr;
|
|
|
+import com.ruoyi.biz.domain.TwinDevice;
|
|
|
+import com.ruoyi.biz.domain.TwinRecordAlarms;
|
|
|
import com.ruoyi.biz.service.*;
|
|
|
import com.ruoyi.biz.service.impl.AsyncServiceImpl;
|
|
|
import com.ruoyi.biz.tools.Tools;
|
|
|
+import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
import com.ruoyi.common.core.domain.R;
|
|
|
+import com.ruoyi.common.utils.CacheUtils;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.system.service.ISysConfigService;
|
|
@@ -27,7 +32,6 @@ import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.ParseException;
|
|
|
import java.time.LocalDate;
|
|
@@ -79,143 +83,26 @@ public class ApiController extends BaseController {
|
|
|
@GetMapping("/index")
|
|
|
@CrossOrigin(origins = "*")
|
|
|
public R<IndexData> index() {
|
|
|
- TwinCalc2hr calc2hr = calc2hrService.calcToday();
|
|
|
- IndexData indexData = new IndexData();
|
|
|
- IndexEfficiency efficiency = new IndexEfficiency(calc2hr);
|
|
|
- indexData.setEfficiency(efficiency);
|
|
|
- /*
|
|
|
- *获取前面6天的数据,加上当天数据
|
|
|
- */
|
|
|
- LocalDate localDate = LocalDate.now().minusDays(6);
|
|
|
- Date date = Date.from(localDate.atStartOfDay(ZoneOffset.of("+8")).toInstant());
|
|
|
- List<TwinCalcDay> list = twinCalcDayService.selectTwinCalcDayListByTime(date);
|
|
|
- TwinCalcDay today = new TwinCalcDay();
|
|
|
- today.convert(calc2hr);
|
|
|
- list.add(today);
|
|
|
- List<WeekData> weekDataList = new ArrayList<>();
|
|
|
- list.forEach(day -> {
|
|
|
- WeekData weekData = new WeekData();
|
|
|
- weekData.convert(day);
|
|
|
- weekDataList.add(weekData);
|
|
|
-
|
|
|
- });
|
|
|
- indexData.setWeekData(weekDataList);
|
|
|
- return R.ok(indexData);
|
|
|
+ Object d = CacheUtils.get(Constants.IOT_TOKEN, Constants.INDEX_CALC);
|
|
|
+ if (d != null) {
|
|
|
+ IndexData indexData = (IndexData) d;
|
|
|
+ return R.ok(indexData);
|
|
|
+ } else {
|
|
|
+ return R.fail();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@ApiOperation("首页告警数据")
|
|
|
@GetMapping("/alarm")
|
|
|
@CrossOrigin(origins = "*")
|
|
|
public R<IndexData> alarm() {
|
|
|
- IndexData indexData = new IndexData();
|
|
|
- List<IndexAlarm> alarmList = new ArrayList<>();
|
|
|
- List<IndexPan> panList = new ArrayList<>();
|
|
|
- int stop1 = 0, stop2 = 0, stop6 = 0, stop8 = 0;
|
|
|
- iotService.getToken();
|
|
|
- List<TwinDevice> list = deviceService.selectTwinDeviceList(new TwinDevice());
|
|
|
- Map<String, Long> panMap = new HashMap<>(16);
|
|
|
- panHeadInfoService.selectTwinPanHeadInfoList(new TwinPanHeadInfo()).forEach(pan -> {
|
|
|
- String key = pan.getDeviceId() + "_" + pan.getPhNum();
|
|
|
- panMap.put(key, pan.getPhMax());
|
|
|
- });
|
|
|
- List<Future<Map<String, Object>>> futureList = new ArrayList<>();
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- TwinDevice twinDevice = list.get(i);
|
|
|
- futureList.add(asyncService.currData(twinDevice));
|
|
|
- }
|
|
|
- try {
|
|
|
- for (Future<Map<String, Object>> future : futureList) {
|
|
|
- Map<String, Object> map = future.get();
|
|
|
- TwinDevice device = (TwinDevice) map.get("device");
|
|
|
- int total = (int) map.get("total");
|
|
|
- if (total == 0) {
|
|
|
- //可能会出现接口返回无数据的情况
|
|
|
- continue;
|
|
|
- }
|
|
|
- int data4 = (int) map.get("Capacity_data_4");
|
|
|
- if (data4 == 0) {
|
|
|
- //Capacity_data_4,如果设定落布米数为0,则证明当前数据无效
|
|
|
- //不能跟上面判断合并,不然报空指针
|
|
|
- continue;
|
|
|
- }
|
|
|
- for (int i = 1; i <= 26; i++) {
|
|
|
- boolean flag = (boolean) map.get("Alarm_unit_" + i);
|
|
|
- if (flag) {
|
|
|
- IndexAlarm indexAlarm = new IndexAlarm();
|
|
|
- indexAlarm.setCode(device.getDeviceCode());
|
|
|
- indexAlarm.setName(device.getDeviceName());
|
|
|
- indexAlarm.setType(i);
|
|
|
- alarmList.add(indexAlarm);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- int alarm27 = (int) map.get("Alarm_unit_27");
|
|
|
- if (alarm27 != 0) {
|
|
|
- IndexAlarm indexAlarm = new IndexAlarm();
|
|
|
- indexAlarm.setCode(device.getDeviceCode());
|
|
|
- indexAlarm.setName(device.getDeviceName());
|
|
|
- indexAlarm.setType(27);
|
|
|
- alarmList.add(indexAlarm);
|
|
|
- }
|
|
|
-
|
|
|
- int stopStatus = (int) map.get("Capacity_data_48");
|
|
|
- switch (stopStatus) {
|
|
|
- case 1:
|
|
|
- stop1++;
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- stop2++;
|
|
|
- break;
|
|
|
- case 6:
|
|
|
- stop6++;
|
|
|
- break;
|
|
|
- default:
|
|
|
- }
|
|
|
-
|
|
|
- int[] curr = new int[5];
|
|
|
- int[] max = new int[5];
|
|
|
- float[] panPercent = new float[5];
|
|
|
- for (int i = 0; i < curr.length; i++) {
|
|
|
- int pos = 15 + i;
|
|
|
- curr[i] = (int) map.get("Capacity_data_" + pos);
|
|
|
- String key = device.getId() + "_" + (i + 1);
|
|
|
- max[i] = 15000;
|
|
|
- if (panMap.get(key) != null) {
|
|
|
- max[i] = Math.toIntExact(panMap.get(key));
|
|
|
- }
|
|
|
-
|
|
|
- panPercent[i] = BigDecimal.valueOf(curr[i] * 100).divide(BigDecimal.valueOf(max[i]), 2, RoundingMode.HALF_UP).floatValue();
|
|
|
- if (panPercent[i] < 20) {
|
|
|
- stop8++;
|
|
|
- }
|
|
|
- if (panPercent[i] > 100) {
|
|
|
- panPercent[i] = 100;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- IndexPan pan = new IndexPan();
|
|
|
- pan.setCode(device.getDeviceCode());
|
|
|
- pan.setName(device.getDeviceName());
|
|
|
- pan.setPanPercent(panPercent);
|
|
|
- panList.add(pan);
|
|
|
- }
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (ExecutionException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ Object d = CacheUtils.get(Constants.IOT_TOKEN, Constants.INDEX_ALARM);
|
|
|
+ if (d != null) {
|
|
|
+ IndexData indexData = (IndexData) d;
|
|
|
+ return R.ok(indexData);
|
|
|
+ } else {
|
|
|
+ return R.fail();
|
|
|
}
|
|
|
- indexData.setAlarm(alarmList);
|
|
|
- indexData.setPan(panList);
|
|
|
- IndexDevice device = new IndexDevice();
|
|
|
- device.setTotal(Integer.parseInt(configService.selectConfigByKey("sys.device.total")));
|
|
|
- device.setOnline(list.size());
|
|
|
- device.setStop1(stop1);
|
|
|
- device.setStop2(stop2);
|
|
|
- device.setStop6(stop6);
|
|
|
- device.setStop8(stop8);
|
|
|
- device.setAlarm(alarmList.size());
|
|
|
- indexData.setDevice(device);
|
|
|
- return R.ok(indexData);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("设备具体数据")
|