|
@@ -4,15 +4,15 @@ import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.project.common.utils.StringUtils;
|
|
import com.project.common.utils.StringUtils;
|
|
import com.project.zcustom.domain.addional.LargeBuildingControl;
|
|
import com.project.zcustom.domain.addional.LargeBuildingControl;
|
|
-import com.project.zcustom.domain.addional.LargeBuildingControlAmmeterDetail;
|
|
|
|
import com.project.zcustom.mapper.unit.PlatBuildingMapper;
|
|
import com.project.zcustom.mapper.unit.PlatBuildingMapper;
|
|
import com.project.zcustom.service.service.smart.IPlatBuildingService;
|
|
import com.project.zcustom.service.service.smart.IPlatBuildingService;
|
|
-import com.project.zcustom.tools.ApiUrlConfig;
|
|
|
|
-import com.project.zcustom.tools.BuildingService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -21,15 +21,17 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
@Autowired
|
|
@Autowired
|
|
private PlatBuildingMapper platBuildingMapper;
|
|
private PlatBuildingMapper platBuildingMapper;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private BuildingService buildingService;
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getPowerAndWaterMonth(){
|
|
public List<Map<String, Object>> getPowerAndWaterMonth(){
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
|
|
String json = platBuildingMapper.getPowerAndWaterMonth();
|
|
String json = platBuildingMapper.getPowerAndWaterMonth();
|
|
if (StringUtils.isEmpty(json)){
|
|
if (StringUtils.isEmpty(json)){
|
|
- return null;
|
|
|
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
|
+ data.put("name", "water");
|
|
|
|
+ data.put("value", 0);
|
|
|
|
+ resultList.add(data);
|
|
|
|
+ return resultList;
|
|
}
|
|
}
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
@@ -49,7 +51,12 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
String json = platBuildingMapper.getAirCondition();
|
|
String json = platBuildingMapper.getAirCondition();
|
|
if (StringUtils.isEmpty(json)){
|
|
if (StringUtils.isEmpty(json)){
|
|
- return null;
|
|
|
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
|
+ data.put("name", "温度");
|
|
|
|
+ data.put("valueIn", 0);
|
|
|
|
+ data.put("valueOut", 0);
|
|
|
|
+ resultList.add(data);
|
|
|
|
+ return resultList;
|
|
}
|
|
}
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
@@ -71,7 +78,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
String json = platBuildingMapper.getTarget();
|
|
String json = platBuildingMapper.getTarget();
|
|
if (StringUtils.isEmpty(json)){
|
|
if (StringUtils.isEmpty(json)){
|
|
- return null;
|
|
|
|
|
|
+ return resultList;
|
|
}
|
|
}
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
@@ -102,7 +109,7 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
String json = platBuildingMapper.useElectricity();
|
|
String json = platBuildingMapper.useElectricity();
|
|
if (StringUtils.isEmpty(json)){
|
|
if (StringUtils.isEmpty(json)){
|
|
- return null;
|
|
|
|
|
|
+ return resultList;
|
|
}
|
|
}
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
@@ -119,15 +126,17 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> greenElectricity(){
|
|
public Map<String, Object> greenElectricity(){
|
|
-
|
|
|
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
String json = platBuildingMapper.greenElectricity();
|
|
String json = platBuildingMapper.greenElectricity();
|
|
if (StringUtils.isEmpty(json)){
|
|
if (StringUtils.isEmpty(json)){
|
|
- return null;
|
|
|
|
|
|
+ data.put("publicEnergy", 0);
|
|
|
|
+ data.put("grennEnergy", 0);
|
|
|
|
+ return data;
|
|
}
|
|
}
|
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
|
String publicEnergy = jsonObject.getString("publicEnergy");
|
|
String publicEnergy = jsonObject.getString("publicEnergy");
|
|
String grennEnergy = jsonObject.getString("grennEnergy");
|
|
String grennEnergy = jsonObject.getString("grennEnergy");
|
|
- Map<String, Object> data = new HashMap<>();
|
|
|
|
|
|
+
|
|
data.put("publicEnergy", publicEnergy);
|
|
data.put("publicEnergy", publicEnergy);
|
|
data.put("grennEnergy", grennEnergy);
|
|
data.put("grennEnergy", grennEnergy);
|
|
return data;
|
|
return data;
|
|
@@ -136,8 +145,8 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
public List<Map<String, Object>> carbon(){
|
|
public List<Map<String, Object>> carbon(){
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
String json = platBuildingMapper.carbon();
|
|
String json = platBuildingMapper.carbon();
|
|
- if (json == null || json.isEmpty()) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ if ( StringUtils.isBlank(json)) {
|
|
|
|
+ return resultList;
|
|
}
|
|
}
|
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
|
JSONArray dataArray = jsonObject.getJSONArray("data");
|
|
JSONArray dataArray = jsonObject.getJSONArray("data");
|
|
@@ -156,8 +165,8 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
public Map<String, Object> energyYear(){
|
|
public Map<String, Object> energyYear(){
|
|
Map<String, Object> res = new HashMap<>();
|
|
Map<String, Object> res = new HashMap<>();
|
|
String json = platBuildingMapper.energyYear();
|
|
String json = platBuildingMapper.energyYear();
|
|
- if (json == null || json.isEmpty()) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ if (StringUtils.isBlank(json)) {
|
|
|
|
+ return res;
|
|
}
|
|
}
|
|
JSONObject dataObject = JSONObject.parseObject(json);
|
|
JSONObject dataObject = JSONObject.parseObject(json);
|
|
String yearTotal = dataObject.getString("yearTotal");
|
|
String yearTotal = dataObject.getString("yearTotal");
|
|
@@ -182,8 +191,8 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
public Map<String, Object> powerYear(){
|
|
public Map<String, Object> powerYear(){
|
|
Map<String, Object> res = new HashMap<>();
|
|
Map<String, Object> res = new HashMap<>();
|
|
String json = platBuildingMapper.powerYear();
|
|
String json = platBuildingMapper.powerYear();
|
|
- if (json == null || json.isEmpty()) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ if (StringUtils.isBlank(json)) {
|
|
|
|
+ return res;
|
|
}
|
|
}
|
|
JSONObject dataObject = JSONObject.parseObject(json);
|
|
JSONObject dataObject = JSONObject.parseObject(json);
|
|
String yearTotal = dataObject.getString("yearTotal");
|
|
String yearTotal = dataObject.getString("yearTotal");
|
|
@@ -208,8 +217,8 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
public Map<String, Object> waterYear(){
|
|
public Map<String, Object> waterYear(){
|
|
Map<String, Object> res = new HashMap<>();
|
|
Map<String, Object> res = new HashMap<>();
|
|
String json = platBuildingMapper.waterYear();
|
|
String json = platBuildingMapper.waterYear();
|
|
- if (json == null || json.isEmpty()) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ if (StringUtils.isBlank(json)) {
|
|
|
|
+ return res;
|
|
}
|
|
}
|
|
JSONObject dataObject = JSONObject.parseObject(json);
|
|
JSONObject dataObject = JSONObject.parseObject(json);
|
|
String yearTotal = dataObject.getString("yearTotal");
|
|
String yearTotal = dataObject.getString("yearTotal");
|
|
@@ -234,8 +243,11 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
public Map<String, Object> frequency(){
|
|
public Map<String, Object> frequency(){
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
String json = platBuildingMapper.frequency();
|
|
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> xList = new ArrayList<>();
|
|
List<String> yList = new ArrayList<>();
|
|
List<String> yList = new ArrayList<>();
|
|
@@ -255,15 +267,19 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
|
|
|
|
public Map<String, Object> patrol(){
|
|
public Map<String, Object> patrol(){
|
|
String json = platBuildingMapper.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);
|
|
JSONObject jsonObject = JSONObject.parseObject(json);
|
|
JSONArray dataArray = jsonObject.getJSONArray("data");
|
|
JSONArray dataArray = jsonObject.getJSONArray("data");
|
|
JSONObject dataItem = dataArray.getJSONObject(0);
|
|
JSONObject dataItem = dataArray.getJSONObject(0);
|
|
JSONArray patrolArray = dataItem.getJSONArray("data");
|
|
JSONArray patrolArray = dataItem.getJSONArray("data");
|
|
JSONArray monthArray = jsonObject.getJSONArray("xAxis");
|
|
JSONArray monthArray = jsonObject.getJSONArray("xAxis");
|
|
- Map<String, Object> data = new HashMap<>();
|
|
|
|
|
|
+
|
|
data.put("patrolArray", patrolArray.toJavaList(Double.class));
|
|
data.put("patrolArray", patrolArray.toJavaList(Double.class));
|
|
data.put("monthArray", monthArray.toJavaList(String.class));
|
|
data.put("monthArray", monthArray.toJavaList(String.class));
|
|
return data;
|
|
return data;
|
|
@@ -272,8 +288,8 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
public List<Map<String, Object>> patrolPoint(){
|
|
public List<Map<String, Object>> patrolPoint(){
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
String json = platBuildingMapper.patrolPoint();
|
|
String json = platBuildingMapper.patrolPoint();
|
|
- if (json == null || json.isEmpty()) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ if (StringUtils.isBlank(json)) {
|
|
|
|
+ return resultList;
|
|
}
|
|
}
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
JSONArray dataArray = JSONArray.parseArray(json);
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
for (int i = 0; i < dataArray.size(); i++) {
|
|
@@ -480,4 +496,18 @@ public class PlatBuildingServiceImpl implements IPlatBuildingService {
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private static String[] getLastSixMonths() {
|
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
|
+ // 自定义格式化模式,确保月份没有前导零并附加“月”字
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M'月'");
|
|
|
|
+ String[] monthsArray = new String[6]; // 创建一个长度为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;
|
|
|
|
+ }
|
|
}
|
|
}
|