Commit b5426fa9 authored by 廖旭伟's avatar 廖旭伟

修改站点树接口返回值结构,增加设备统计

parent 9884d93c
...@@ -52,6 +52,14 @@ public class SiteTreeSelectVO implements Serializable { ...@@ -52,6 +52,14 @@ public class SiteTreeSelectVO implements Serializable {
private String icon; private String icon;
/** 层级 */ /** 层级 */
private Integer level; private Integer level;
/** 地址 */
private String detailAddress;
/** 设备总数 */
private Integer deviceTotal;
/** 设备在线数 */
private Integer onlineTotal;
/** 设备离线数 */
private Integer offlineTotal;
/** /**
* 子节点 * 子节点
...@@ -60,4 +68,21 @@ public class SiteTreeSelectVO implements Serializable { ...@@ -60,4 +68,21 @@ public class SiteTreeSelectVO implements Serializable {
private Integer siteCount; private Integer siteCount;
public SiteTreeSelectVO(){
this.deviceTotal = 0;
this.onlineTotal = 0;
this.offlineTotal = 0;
}
public void deviceTotalAdd(int i) {
this.deviceTotal += i;
}
public void onlineTotalAdd(int i) {
this.onlineTotal += i;
}
public void offlineTotalAdd(int i) {
this.offlineTotal += i;
}
} }
...@@ -14,13 +14,16 @@ import com.mortals.xhx.common.code.YesNoEnum; ...@@ -14,13 +14,16 @@ import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.ParamKey; import com.mortals.xhx.common.key.ParamKey;
import com.mortals.xhx.common.pdu.RespData; import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.app.AppPdu; import com.mortals.xhx.common.pdu.app.AppPdu;
import com.mortals.xhx.common.pdu.device.DevicePdu;
import com.mortals.xhx.common.pdu.site.SiteTreeSelectVO; import com.mortals.xhx.common.pdu.site.SiteTreeSelectVO;
import com.mortals.xhx.feign.app.IAppFeign; import com.mortals.xhx.feign.app.IAppFeign;
import com.mortals.xhx.feign.base.IApiBaseManagerFeign; import com.mortals.xhx.feign.base.IApiBaseManagerFeign;
import com.mortals.xhx.feign.base.pdu.SitePdu; import com.mortals.xhx.feign.base.pdu.SitePdu;
import com.mortals.xhx.feign.device.IDeviceFeign;
import com.mortals.xhx.feign.rsp.ApiResp; import com.mortals.xhx.feign.rsp.ApiResp;
import com.mortals.xhx.feign.site.ISiteFeign; import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.apps.model.AppsInfoEntity; import com.mortals.xhx.module.apps.model.AppsInfoEntity;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.sst.model.SstAppsEntity; import com.mortals.xhx.module.sst.model.SstAppsEntity;
import com.mortals.xhx.module.sst.service.SstAppsDeskService; import com.mortals.xhx.module.sst.service.SstAppsDeskService;
import com.mortals.xhx.module.sst.service.SstAppsService; import com.mortals.xhx.module.sst.service.SstAppsService;
...@@ -72,6 +75,10 @@ public class SstBasicController extends BaseCRUDJsonBodyMappingController<SstBas ...@@ -72,6 +75,10 @@ public class SstBasicController extends BaseCRUDJsonBodyMappingController<SstBas
private ISiteFeign iSiteFeign; private ISiteFeign iSiteFeign;
@Autowired @Autowired
private IAppFeign appFeign; private IAppFeign appFeign;
@Autowired
private IDeviceFeign deviceFeign;
@Autowired
private ISiteFeign siteFeign;
public SstBasicController(){ public SstBasicController(){
super.setModuleDesc( "基础配置"); super.setModuleDesc( "基础配置");
...@@ -192,6 +199,38 @@ public class SstBasicController extends BaseCRUDJsonBodyMappingController<SstBas ...@@ -192,6 +199,38 @@ public class SstBasicController extends BaseCRUDJsonBodyMappingController<SstBas
if (apiResp.getCode() != YesNoEnum.YES.getValue()) { if (apiResp.getCode() != YesNoEnum.YES.getValue()) {
throw new AppException("获取用户站点列表树数据失败:" + apiResp.getMsg()); throw new AppException("获取用户站点列表树数据失败:" + apiResp.getMsg());
} }
com.mortals.xhx.common.pdu.site.SitePdu sitePdu = new com.mortals.xhx.common.pdu.site.SitePdu();
sitePdu.setSize(-1);
Rest<RespData<List<com.mortals.xhx.common.pdu.site.SitePdu>>> result = siteFeign.list(sitePdu);
Map<Long,String> siteMap = new HashMap<>();
if(result.getCode() > 0) {
for(com.mortals.xhx.common.pdu.site.SitePdu item:result.getData().getData()){
siteMap.put(item.getId(),item.getDetailAddress());
}
}
DevicePdu devicePdu = new DevicePdu();
devicePdu.setSize(-1);
devicePdu.setProductName("%自助服务终端%");
Rest<RespData<List<DevicePdu>>> deviceRest = deviceFeign.list(devicePdu);
Map<Long,SiteTreeSelectVO> siteDeviceMap = new HashMap<>();
if(deviceRest.getCode() > 0) {
for(DevicePdu device:deviceRest.getData().getData()){
SiteTreeSelectVO vo;
if(siteDeviceMap.containsKey(device.getSiteId())){
vo = siteDeviceMap.get(device.getSiteId());
}else {
vo = new SiteTreeSelectVO();
}
vo.deviceTotalAdd(1);
if(device.getDeviceStatus()==1){
vo.offlineTotalAdd(1);
}
if(device.getDeviceStatus()==2){
vo.onlineTotalAdd(1);
}
siteDeviceMap.put(device.getSiteId(),vo);
}
}
if (apiResp.getData().get("siteTree") != null) { if (apiResp.getData().get("siteTree") != null) {
List<SiteTreeSelectVO> resultList = JSONObject.parseArray(apiResp.getData().get("siteTree").toString(),SiteTreeSelectVO.class); List<SiteTreeSelectVO> resultList = JSONObject.parseArray(apiResp.getData().get("siteTree").toString(),SiteTreeSelectVO.class);
SiteTreeSelectVO rootNode = new SiteTreeSelectVO(); SiteTreeSelectVO rootNode = new SiteTreeSelectVO();
...@@ -203,7 +242,7 @@ public class SstBasicController extends BaseCRUDJsonBodyMappingController<SstBas ...@@ -203,7 +242,7 @@ public class SstBasicController extends BaseCRUDJsonBodyMappingController<SstBas
rootNode.setIsLeaf(false); rootNode.setIsLeaf(false);
rootNode.setLatitude("30.595081"); rootNode.setLatitude("30.595081");
rootNode.setLongitude("104.062983"); rootNode.setLongitude("104.062983");
rootNode.setSiteCount(getChildrenCount(resultList,2)-1); rootNode.setSiteCount(getChildrenCount(resultList,2,siteMap,siteDeviceMap)-1);
rootNode.setChildren(resultList); rootNode.setChildren(resultList);
rootNode.setLevel(1); rootNode.setLevel(1);
List<SiteTreeSelectVO> dataList = new ArrayList<>(); List<SiteTreeSelectVO> dataList = new ArrayList<>();
...@@ -226,13 +265,22 @@ public class SstBasicController extends BaseCRUDJsonBodyMappingController<SstBas ...@@ -226,13 +265,22 @@ public class SstBasicController extends BaseCRUDJsonBodyMappingController<SstBas
return ret; return ret;
} }
private static Integer getChildrenCount(List<SiteTreeSelectVO> children,int initLevel){ private static Integer getChildrenCount(List<SiteTreeSelectVO> children,int initLevel,Map<Long,String> siteMap,Map<Long,SiteTreeSelectVO> siteDeviceMap){
if(CollectionUtils.isEmpty(children)) { if(CollectionUtils.isEmpty(children)) {
return 1; return 1;
}else { }else {
int size = 1; int size = 1;
for (SiteTreeSelectVO vo:children){ for (SiteTreeSelectVO vo:children){
int c = getChildrenCount(vo.getChildren(),initLevel+1); int c = getChildrenCount(vo.getChildren(),initLevel+1,siteMap,siteDeviceMap);
if(vo.getType().equals("site")){
Long key = DataUtil.converStr2Long(vo.getId(),0L);
vo.setDetailAddress(siteMap.get(key));
if(siteDeviceMap.containsKey(key)) {
vo.setDeviceTotal(siteDeviceMap.get(key).getDeviceTotal());
vo.setOnlineTotal(siteDeviceMap.get(key).getOnlineTotal());
vo.setOfflineTotal(siteDeviceMap.get(key).getOfflineTotal());
}
}
vo.setSiteCount(c); vo.setSiteCount(c);
vo.setLevel(initLevel); vo.setLevel(initLevel);
size += c; size += c;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment