|
@@ -3,6 +3,7 @@ package com.sky.ioc.service.space.impl;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.sky.ioc.config.RestTemplateConfig;
|
|
|
import com.sky.ioc.entity.Indeicator;
|
|
|
import com.sky.ioc.entity.Label;
|
|
|
import com.sky.ioc.entity.domain.space.*;
|
|
@@ -18,15 +19,15 @@ import com.sky.ioc.tool.DateUtil;
|
|
|
import com.sky.ioc.tool.GeneralMethod;
|
|
|
import com.sky.ioc.tool.MathUtils;
|
|
|
import com.sky.ioc.tool.ReturnMsg;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.NumberFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -38,6 +39,7 @@ import java.util.stream.Collectors;
|
|
|
* @Date 2023/2/22 11:44
|
|
|
**/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class SpaceServiceImpl implements SpaceService {
|
|
|
|
|
|
@Autowired
|
|
@@ -58,6 +60,11 @@ public class SpaceServiceImpl implements SpaceService {
|
|
|
@Autowired
|
|
|
BuildingRoomMapper buildingRoomMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RestTemplateConfig restTemplateConfig;
|
|
|
+
|
|
|
+ final static String SPACE_ROOM_URL="/api/statistics/space/room/getRoomDistributions";
|
|
|
+
|
|
|
/**
|
|
|
* TODO 智能看板 -- 楼宇态势
|
|
|
*
|
|
@@ -137,6 +144,84 @@ public class SpaceServiceImpl implements SpaceService {
|
|
|
return ReturnMsg.ok(indeicator);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ReturnMsg getFloorCoreIndicatorsData(IocParam iocParam) {
|
|
|
+ String append = "?floorId="+iocParam.getFloorId();
|
|
|
+ if(iocParam.getFloorId()==null){
|
|
|
+ append="";
|
|
|
+ }
|
|
|
+ String url = restTemplateConfig.addBaseUrl(SPACE_ROOM_URL)+append;
|
|
|
+ RestTemplate restTemplate = restTemplateConfig.build();
|
|
|
+ // 发送GET请求
|
|
|
+ ResponseEntity<Map> responseEntity = restTemplate.getForEntity(url, Map.class);
|
|
|
+ // 获取响应对象里的 body 对象
|
|
|
+ Map<String, Object> body = responseEntity.getBody();
|
|
|
+ // 获取状态码
|
|
|
+ Integer code = (Integer)body.get("code");
|
|
|
+ // 获取响应信息
|
|
|
+ String message = (String)body.get("msg");
|
|
|
+ if(code==200){
|
|
|
+ Indeicator indeicator = new Indeicator();
|
|
|
+ List<JSONObject> objects = indeicator.getList();
|
|
|
+
|
|
|
+ LinkedHashMap data = (LinkedHashMap) body.get("data");
|
|
|
+ ArrayList dataList = (ArrayList)data.get("dataList");
|
|
|
+ for(int i=0;i<dataList.size();i++){
|
|
|
+ LinkedHashMap json = (LinkedHashMap) dataList.get(i);
|
|
|
+ if(json.get("name").toString().equals("办公区")){
|
|
|
+ objects.get(2).put("value", json.get("buildingArea"));
|
|
|
+ }
|
|
|
+ if(json.get("name").toString().equals("会议室")){
|
|
|
+ objects.get(3).put("value", json.get("buildingArea"));
|
|
|
+ }
|
|
|
+ if(json.get("name").toString().equals("其他")){
|
|
|
+ objects.add(new JSONObject());
|
|
|
+ objects.get(4).put("value", json.get("buildingArea"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String floorCode = "";
|
|
|
+ BuildingFloor floor = null;
|
|
|
+ Integer result =0;
|
|
|
+ Long totalStation = 0l;
|
|
|
+ List<BuildingRoom> rooms = null;
|
|
|
+ if(iocParam.getFloorId()==null){
|
|
|
+ rooms = buildingRoomMapper.selectList(null);
|
|
|
+ }else{
|
|
|
+ floorCode = iocParam.getFloorId()+"F";
|
|
|
+ if(iocParam.getFloorId()<0){
|
|
|
+ floorCode = "B"+Math.abs(iocParam.getFloorId());
|
|
|
+ }
|
|
|
+ floor = buildingFloorMapper.selectOne(new LambdaQueryWrapper<BuildingFloor>().eq(BuildingFloor::getCode,floorCode));
|
|
|
+ if(floor!=null){
|
|
|
+ rooms = buildingRoomMapper.selectList(new LambdaQueryWrapper<BuildingRoom>().eq(BuildingRoom::getFloorId,floor.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(rooms!=null&&rooms.size()>0){
|
|
|
+ List<Integer> ids = rooms.stream().map(BuildingRoom::getId).collect(Collectors.toList());
|
|
|
+ totalStation = buildingStationMapper.selectCount(new LambdaQueryWrapper<BuildingStation>().in(BuildingStation::getRoomId,ids));
|
|
|
+ Long usedStation = buildingStationMapper.selectCount(new LambdaQueryWrapper<BuildingStation>().in(BuildingStation::getRoomId,ids)
|
|
|
+ .eq(BuildingStation::getStatus,2));
|
|
|
+ // 创建一个数值格式化对象
|
|
|
+ NumberFormat numberFormat = NumberFormat.getInstance();
|
|
|
+ // 设置精确到小数点后2位
|
|
|
+ numberFormat.setMaximumFractionDigits(0);
|
|
|
+ if (totalStation>0) {
|
|
|
+ result = Integer.parseInt(numberFormat.format((float) usedStation / (float) totalStation * 100));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ objects.get(0).put("value", result);
|
|
|
+ objects.get(1).put("value", totalStation);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return ReturnMsg.ok(indeicator);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ log.info("获取餐厅消费分析数据:"+message);
|
|
|
+ return ReturnMsg.fail(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ReturnMsg getAccessPersonnel(IocParam iocParam) {
|
|
|
List<AccessSpace> list = accessSpaceMapper.getByTier(iocParam);
|