|
@@ -3,10 +3,9 @@ package com.ruoyi.biz.controller;
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
import com.ruoyi.biz.domain.*;
|
|
import com.ruoyi.biz.domain.*;
|
|
-import com.ruoyi.biz.service.IIotService;
|
|
|
|
-import com.ruoyi.biz.service.ITwinCalcDayService;
|
|
|
|
-import com.ruoyi.biz.service.ITwinDataService;
|
|
|
|
-import com.ruoyi.biz.service.ITwinDeviceService;
|
|
|
|
|
|
+import com.ruoyi.biz.service.*;
|
|
|
|
+import com.ruoyi.biz.service.impl.AsyncServiceImpl;
|
|
|
|
+import com.ruoyi.biz.service.impl.IotTokenServiceImpl;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.domain.R;
|
|
import com.ruoyi.common.core.domain.R;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
@@ -17,6 +16,8 @@ import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
|
+import java.util.concurrent.Future;
|
|
|
|
|
|
/**
|
|
/**
|
|
* swagger 用户测试方法
|
|
* swagger 用户测试方法
|
|
@@ -30,73 +31,39 @@ public class ApiController extends BaseController {
|
|
@Resource
|
|
@Resource
|
|
private ITwinCalcDayService twinCalcDayService;
|
|
private ITwinCalcDayService twinCalcDayService;
|
|
@Resource
|
|
@Resource
|
|
|
|
+ private ITwinCalc2hrService calc2hrService;
|
|
|
|
+ @Resource
|
|
private ITwinDataService twinDataService;
|
|
private ITwinDataService twinDataService;
|
|
@Resource
|
|
@Resource
|
|
private ITwinDeviceService deviceService;
|
|
private ITwinDeviceService deviceService;
|
|
@Resource
|
|
@Resource
|
|
private IIotService iotService;
|
|
private IIotService iotService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IotTokenServiceImpl iotTokenService;
|
|
|
|
+ @Resource
|
|
|
|
+ private AsyncServiceImpl asyncService;
|
|
|
|
|
|
- @ApiOperation("首页数据")
|
|
|
|
|
|
+ @ApiOperation("首页统计数据")
|
|
@GetMapping("/index")
|
|
@GetMapping("/index")
|
|
@CrossOrigin(origins = "*")
|
|
@CrossOrigin(origins = "*")
|
|
public R<IndexData> index() {
|
|
public R<IndexData> index() {
|
|
|
|
+ TwinCalc2hr calc2hr = calc2hrService.calcToday();
|
|
IndexData indexData = new IndexData();
|
|
IndexData indexData = new IndexData();
|
|
IndexEfficiency efficiency = new IndexEfficiency();
|
|
IndexEfficiency efficiency = new IndexEfficiency();
|
|
- Float aTime = new Random().nextInt(1200) / 100f;
|
|
|
|
- Float bTime = new Random().nextInt(1200) / 100f;
|
|
|
|
- Float aLength = new Random().nextInt(90000) / 100f;
|
|
|
|
- Float bLength = new Random().nextInt(90000) / 100f;
|
|
|
|
- Float tLength = aLength + bLength;
|
|
|
|
- Float aWeight = BigDecimal.valueOf(aLength * 3000 / 1000 / 1000).setScale(2, RoundingMode.HALF_UP).floatValue();
|
|
|
|
- Float bWeight = BigDecimal.valueOf(bLength * 3000 / 1000 / 1000).setScale(2, RoundingMode.HALF_UP).floatValue();
|
|
|
|
- Float tWeight = BigDecimal.valueOf(aWeight + bWeight).setScale(2, RoundingMode.HALF_UP).floatValue();
|
|
|
|
Float ae = new Random().nextInt(2000) / 100f + 80f;
|
|
Float ae = new Random().nextInt(2000) / 100f + 80f;
|
|
Float be = new Random().nextInt(2000) / 100f + 80f;
|
|
Float be = new Random().nextInt(2000) / 100f + 80f;
|
|
- Float te = ae + be;
|
|
|
|
- efficiency.setTotalLength(tLength);
|
|
|
|
- efficiency.setTotalWeight(tWeight);
|
|
|
|
- efficiency.setATime(aTime);
|
|
|
|
- efficiency.setALength(aLength);
|
|
|
|
- efficiency.setAWeight(aWeight);
|
|
|
|
|
|
+ efficiency.setTotalLength(calc2hr.getLengthA().add(calc2hr.getLengthB()).floatValue());
|
|
|
|
+ efficiency.setTotalWeight(calc2hr.getWeightA().add(calc2hr.getWeightB()).floatValue());
|
|
|
|
+ efficiency.setATime(calc2hr.getOpenTimeA().floatValue());
|
|
|
|
+ efficiency.setALength(calc2hr.getLengthA().floatValue());
|
|
|
|
+ efficiency.setAWeight(calc2hr.getWeightA().floatValue());
|
|
efficiency.setAEfficiency(ae);
|
|
efficiency.setAEfficiency(ae);
|
|
-
|
|
|
|
- efficiency.setBTime(bTime);
|
|
|
|
- efficiency.setBLength(bLength);
|
|
|
|
- efficiency.setBWeight(bWeight);
|
|
|
|
|
|
+ efficiency.setBTime(calc2hr.getOpenTimeB().floatValue());
|
|
|
|
+ efficiency.setBLength(calc2hr.getLengthB().floatValue());
|
|
|
|
+ efficiency.setBWeight(calc2hr.getWeightB().floatValue());
|
|
efficiency.setBEfficiency(be);
|
|
efficiency.setBEfficiency(be);
|
|
indexData.setEfficiency(efficiency);
|
|
indexData.setEfficiency(efficiency);
|
|
- List<IndexAlarm> alarmList = new ArrayList<>();
|
|
|
|
- IndexAlarm indexAlarm = new IndexAlarm();
|
|
|
|
- indexAlarm.setCode("C_2");
|
|
|
|
- indexAlarm.setName("小经编机2号");
|
|
|
|
- indexAlarm.setType(1);
|
|
|
|
- alarmList.add(indexAlarm);
|
|
|
|
- indexAlarm = new IndexAlarm();
|
|
|
|
- indexAlarm.setCode("C_5");
|
|
|
|
- indexAlarm.setName("小经编机5号");
|
|
|
|
- indexAlarm.setType(2);
|
|
|
|
- alarmList.add(indexAlarm);
|
|
|
|
- indexAlarm = new IndexAlarm();
|
|
|
|
- indexAlarm.setCode("C_7");
|
|
|
|
- indexAlarm.setName("小经编机7号");
|
|
|
|
- indexAlarm.setType(25);
|
|
|
|
- alarmList.add(indexAlarm);
|
|
|
|
- indexAlarm = new IndexAlarm();
|
|
|
|
- indexAlarm.setCode("C_8");
|
|
|
|
- indexAlarm.setName("小经编机8号");
|
|
|
|
- indexAlarm.setType(8);
|
|
|
|
- alarmList.add(indexAlarm);
|
|
|
|
- indexAlarm = new IndexAlarm();
|
|
|
|
- indexAlarm.setCode("C_97");
|
|
|
|
- indexAlarm.setName("小经编机97号");
|
|
|
|
- indexAlarm.setType(22);
|
|
|
|
- alarmList.add(indexAlarm);
|
|
|
|
- indexAlarm = new IndexAlarm();
|
|
|
|
- indexAlarm.setCode("C_98");
|
|
|
|
- indexAlarm.setName("小经编机98号");
|
|
|
|
- indexAlarm.setType(15);
|
|
|
|
- alarmList.add(indexAlarm);
|
|
|
|
- indexData.setAlarm(alarmList);
|
|
|
|
|
|
+
|
|
List<WeekData> weekDataList = new ArrayList<>();
|
|
List<WeekData> weekDataList = new ArrayList<>();
|
|
for (int i = 0; i < 7; i++) {
|
|
for (int i = 0; i < 7; i++) {
|
|
WeekData weekData = new WeekData();
|
|
WeekData weekData = new WeekData();
|
|
@@ -136,14 +103,86 @@ public class ApiController extends BaseController {
|
|
// weekDataList.add(weekData);
|
|
// weekDataList.add(weekData);
|
|
// });
|
|
// });
|
|
indexData.setWeekData(weekDataList);
|
|
indexData.setWeekData(weekDataList);
|
|
|
|
+ return R.ok(indexData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation("首页告警数据")
|
|
|
|
+ @GetMapping("/alarm")
|
|
|
|
+ @CrossOrigin(origins = "*")
|
|
|
|
+ public R<IndexData> alarm() {
|
|
|
|
+ IndexData indexData = new IndexData();
|
|
|
|
+ List<IndexAlarm> alarmList = new ArrayList<>();
|
|
|
|
+ int stop1 = 0, stop2 = 0, stop6 = 0;
|
|
|
|
+ iotTokenService.getToken();
|
|
|
|
+ List<TwinDevice> list = deviceService.selectTwinDeviceList(new TwinDevice());
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (map.get("Alarm_unit_27") == null) {
|
|
|
|
+ System.err.println("=======");
|
|
|
|
+ }
|
|
|
|
+ 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:
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ } catch (ExecutionException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ indexData.setAlarm(alarmList);
|
|
|
|
+
|
|
IndexDevice device = new IndexDevice();
|
|
IndexDevice device = new IndexDevice();
|
|
device.setTotal(140);
|
|
device.setTotal(140);
|
|
- device.setOnline(48);
|
|
|
|
- device.setStop1(new Random().nextInt(50));
|
|
|
|
- device.setStop2(new Random().nextInt(50));
|
|
|
|
- device.setStop6(new Random().nextInt(50));
|
|
|
|
- device.setStop8(new Random().nextInt(50));
|
|
|
|
- device.setAlarm(new Random().nextInt(50));
|
|
|
|
|
|
+ device.setOnline(list.size());
|
|
|
|
+ device.setStop1(stop1);
|
|
|
|
+ device.setStop2(stop2);
|
|
|
|
+ device.setStop6(stop6);
|
|
|
|
+ device.setStop8(new Random().nextInt(5));
|
|
|
|
+ device.setAlarm(alarmList.size());
|
|
indexData.setDevice(device);
|
|
indexData.setDevice(device);
|
|
return R.ok(indexData);
|
|
return R.ok(indexData);
|
|
}
|
|
}
|
|
@@ -155,7 +194,6 @@ public class ApiController extends BaseController {
|
|
TwinDevice info = deviceService.selectTwinDeviceByCode(device);
|
|
TwinDevice info = deviceService.selectTwinDeviceByCode(device);
|
|
String table = info.getDevicePath();
|
|
String table = info.getDevicePath();
|
|
String sql = "select last * from " + table;
|
|
String sql = "select last * from " + table;
|
|
- System.err.println(sql);
|
|
|
|
JSONObject jsonObject = iotService.query(sql);
|
|
JSONObject jsonObject = iotService.query(sql);
|
|
JSONObject data = jsonObject.getJSONObject("data");
|
|
JSONObject data = jsonObject.getJSONObject("data");
|
|
JSONArray values = data.getJSONArray("values");
|
|
JSONArray values = data.getJSONArray("values");
|