|
@@ -12,6 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -29,7 +32,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
String json = platBuildingMapper.getPowerAndWaterMonth();
|
|
|
if (StringUtils.isEmpty(json)){
|
|
|
- return null;
|
|
|
+ return resultList;
|
|
|
}
|
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
@@ -49,7 +52,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
String json = platBuildingMapper.getAirCondition();
|
|
|
if (StringUtils.isEmpty(json)){
|
|
|
- return null;
|
|
|
+ return resultList;
|
|
|
}
|
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
@@ -71,7 +74,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
String json = platBuildingMapper.getTarget();
|
|
|
if (StringUtils.isEmpty(json)){
|
|
|
- return null;
|
|
|
+ return resultList;
|
|
|
}
|
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
@@ -102,7 +105,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
String json = platBuildingMapper.useElectricity();
|
|
|
if (StringUtils.isEmpty(json)){
|
|
|
- return null;
|
|
|
+ return resultList;
|
|
|
}
|
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
@@ -119,15 +122,17 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
|
|
|
public Map<String, Object> greenElectricity(){
|
|
|
-
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
String json = platBuildingMapper.greenElectricity();
|
|
|
if (StringUtils.isEmpty(json)){
|
|
|
- return null;
|
|
|
+ data.put("publicEnergy", 0);
|
|
|
+ data.put("grennEnergy", 0);
|
|
|
+ return data;
|
|
|
}
|
|
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
|
|
String publicEnergy = jsonObject.getString("publicEnergy");
|
|
|
String grennEnergy = jsonObject.getString("grennEnergy");
|
|
|
- Map<String, Object> data = new HashMap<>();
|
|
|
+
|
|
|
data.put("publicEnergy", publicEnergy);
|
|
|
data.put("grennEnergy", grennEnergy);
|
|
|
return data;
|
|
@@ -137,7 +142,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
String json = platBuildingMapper.carbon();
|
|
|
if (json == null || json.isEmpty()) {
|
|
|
- return null;
|
|
|
+ return resultList;
|
|
|
}
|
|
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
|
|
JSONArray dataArray = jsonObject.getJSONArray("data");
|
|
@@ -157,7 +162,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
Map<String, Object> res = new HashMap<>();
|
|
|
String json = platBuildingMapper.energyYear();
|
|
|
if (json == null || json.isEmpty()) {
|
|
|
- return null;
|
|
|
+ return res;
|
|
|
}
|
|
|
JSONObject dataObject = JSONObject.parseObject(json);
|
|
|
String yearTotal = dataObject.getString("yearTotal");
|
|
@@ -183,7 +188,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
Map<String, Object> res = new HashMap<>();
|
|
|
String json = platBuildingMapper.powerYear();
|
|
|
if (json == null || json.isEmpty()) {
|
|
|
- return null;
|
|
|
+ return res;
|
|
|
}
|
|
|
JSONObject dataObject = JSONObject.parseObject(json);
|
|
|
String yearTotal = dataObject.getString("yearTotal");
|
|
@@ -209,7 +214,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
Map<String, Object> res = new HashMap<>();
|
|
|
String json = platBuildingMapper.waterYear();
|
|
|
if (json == null || json.isEmpty()) {
|
|
|
- return null;
|
|
|
+ return res;
|
|
|
}
|
|
|
JSONObject dataObject = JSONObject.parseObject(json);
|
|
|
String yearTotal = dataObject.getString("yearTotal");
|
|
@@ -234,8 +239,11 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
public Map<String, Object> frequency(){
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
String json = platBuildingMapper.frequency();
|
|
|
- if (json == null || json.isEmpty()) {
|
|
|
- return null;
|
|
|
+ if ( StringUtils.isBlank(json)) {
|
|
|
+ map.put("xList", this.getLastSixMonths());
|
|
|
+ Integer[] patrolArray = {0,0,0,0,0,0};
|
|
|
+ map.put("yList", patrolArray);
|
|
|
+ return map;
|
|
|
}
|
|
|
List<String> xList = new ArrayList<>();
|
|
|
List<String> yList = new ArrayList<>();
|
|
@@ -255,15 +263,19 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
public Map<String, Object> patrol(){
|
|
|
String json = platBuildingMapper.patrol();
|
|
|
- if (json == null || json.isEmpty()) {
|
|
|
- return null;
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ if (StringUtils.isBlank(json)) {
|
|
|
+ Integer[] patrolArray = {0,0,0,0,0,0};
|
|
|
+ data.put("patrolArray", patrolArray);
|
|
|
+ data.put("monthArray", this.getLastSixMonths());
|
|
|
+ return data;
|
|
|
}
|
|
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
|
|
JSONArray dataArray = jsonObject.getJSONArray("data");
|
|
|
JSONObject dataItem = dataArray.getJSONObject(0);
|
|
|
JSONArray patrolArray = dataItem.getJSONArray("data");
|
|
|
JSONArray monthArray = jsonObject.getJSONArray("xAxis");
|
|
|
- Map<String, Object> data = new HashMap<>();
|
|
|
+
|
|
|
data.put("patrolArray", patrolArray.toJavaList(Double.class));
|
|
|
data.put("monthArray", monthArray.toJavaList(String.class));
|
|
|
return data;
|
|
@@ -273,7 +285,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
String json = platBuildingMapper.patrolPoint();
|
|
|
if (json == null || json.isEmpty()) {
|
|
|
- return null;
|
|
|
+ return resultList;
|
|
|
}
|
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
@@ -435,4 +447,18 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ private String[] getLastSixMonths() {
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+ // 自定义格式化模式,确保月份没有前导零并附加“月”字
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M'月'");
|
|
|
+ String[] monthsArray = new String[6];
|
|
|
+
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ LocalDate firstDayOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ monthsArray[5 - i] = firstDayOfMonth.format(formatter);
|
|
|
+ currentDate = currentDate.minusMonths(1);
|
|
|
+ }
|
|
|
+ return monthsArray;
|
|
|
+ }
|
|
|
}
|