|
@@ -22,13 +22,13 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.ParseException;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.ExecutionException;
|
|
|
-import java.util.concurrent.Future;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -83,13 +83,67 @@ public class ApiController extends BaseController {
|
|
|
if (info == null) {
|
|
|
return R.fail("该设备未接入");
|
|
|
}
|
|
|
- Future<Map<String, Object>> future = asyncService.currData(info);
|
|
|
+ Map<String, Map<String, Object>> curr = redisCache.getCacheObject(CacheConstants.DEVICE_CURRENT);
|
|
|
Map<String, Object> result = new HashMap<>(16);
|
|
|
- try {
|
|
|
- result.put("data", future.get());
|
|
|
- } catch (InterruptedException | ExecutionException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ Map<String, Object> map = curr.get(device);
|
|
|
+ if (map == null) {
|
|
|
+ return R.fail("该设备暂无IOT数据");
|
|
|
}
|
|
|
+ if (device.startsWith("C_")) {
|
|
|
+ float max1 = (float) map.get("Formula_data_26") == 0f ? 20000f : (float) map.get("Formula_data_26");
|
|
|
+ float max2 = (float) map.get("Formula_data_27") == 0f ? 20000f : (float) map.get("Formula_data_27");
|
|
|
+ float max3 = (float) map.get("Formula_data_28") == 0f ? 20000f : (float) map.get("Formula_data_28");
|
|
|
+ float max4 = (float) map.get("Formula_data_29") == 0f ? 20000f : (float) map.get("Formula_data_29");
|
|
|
+ float max5 = (float) map.get("Formula_data_30") == 0f ? 20000f : (float) map.get("Formula_data_30");
|
|
|
+ int q1 = (int) map.get("Capacity_data_15");
|
|
|
+ int q2 = (int) map.get("Capacity_data_16");
|
|
|
+ int q3 = (int) map.get("Capacity_data_17");
|
|
|
+ int q4 = (int) map.get("Capacity_data_18");
|
|
|
+ int q5 = (int) map.get("Capacity_data_19");
|
|
|
+
|
|
|
+ BigDecimal p1 = new BigDecimal(q1 * 100).divide(BigDecimal.valueOf(max1), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal p2 = new BigDecimal(q2 * 100).divide(BigDecimal.valueOf(max2), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal p3 = new BigDecimal(q3 * 100).divide(BigDecimal.valueOf(max3), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal p4 = new BigDecimal(q4 * 100).divide(BigDecimal.valueOf(max4), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal p5 = new BigDecimal(q5 * 100).divide(BigDecimal.valueOf(max5), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+
|
|
|
+ map.put("p1", p1.floatValue() + "%");
|
|
|
+ map.put("p2", p2.floatValue() + "%");
|
|
|
+ map.put("p3", p3.floatValue() + "%");
|
|
|
+ map.put("p4", p4.floatValue() + "%");
|
|
|
+ map.put("p5", p5.floatValue() + "%");
|
|
|
+ } else {
|
|
|
+ int index = 10;
|
|
|
+ int[] max = new int[index];
|
|
|
+ float[] t = new float[index];
|
|
|
+ float[] c = new float[index];
|
|
|
+ int[] q = new int[index];
|
|
|
+
|
|
|
+ for (int i = 0; i < index; i++) {
|
|
|
+ max[i] = (int) map.get("Formula_data_" + (31 + i)) == 0 ? 20000 : (int) map.get("Formula_data_" + (31 + i));
|
|
|
+ t[i] = BigDecimal.valueOf((float) map.get("Capacity_data_" + (71 + i))).setScale(2, RoundingMode.HALF_UP).floatValue();
|
|
|
+ c[i] = BigDecimal.valueOf((float) map.get("Capacity_data_" + (3 + i))).setScale(2, RoundingMode.HALF_UP).floatValue();
|
|
|
+ q[i] = (int) map.get("Capacity_data_" + (15 + i));
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal[] p = new BigDecimal[10];
|
|
|
+ for (int i = 0; i < index; i++) {
|
|
|
+ p[i] = new BigDecimal(q[i] * 100).divide(BigDecimal.valueOf(max[i]), 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
+ int j = i + 5;
|
|
|
+ map.put("p" + (i + 1), String.format("A: %.2f%% B: %.2f%%", p[i].floatValue(), p[j].floatValue()));
|
|
|
+ map.put("Capacity_data_" + (5 + i), "A: " + t[i] + " B: " + t[j]);
|
|
|
+ map.put("Capacity_data_" + (10 + i), "A: " + c[i] + " B: " + c[j]);
|
|
|
+ map.put("Capacity_data_" + (15 + i), "A: " + q[i] + " B: " + q[j]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("data", map);
|
|
|
if (week != null) {
|
|
|
//7点前是属于前一生产天,所以这里直接减7小时即可
|
|
|
LocalDateTime ldt = LocalDateTime.now().minusHours(7);
|