|
@@ -1,6 +1,8 @@
|
|
|
package cn.iocoder.yudao.module.pms.controller.admin.stat;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
|
|
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
@@ -891,5 +893,39 @@ public class IotStaticController {
|
|
|
return success(ImmutableMap.of("xAxis", xAxis, "series", ImmutableList.of(fillResult, waterResult)));
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @PermitAll
|
|
|
+ @GetMapping("/project/{dept}")
|
|
|
+ public CommonResult<List<ImmutableMap<String, ? extends Serializable>>> projectStat(@PathVariable("dept") String dept) {
|
|
|
+ List<DeptRespDTO> deptByName = deptApi.getDeptByName("瑞鹰国际");
|
|
|
+ if (CollUtil.isEmpty(deptByName)) {
|
|
|
+ throw new ServiceException(new ErrorCode(122, "没有部门"));
|
|
|
+ }
|
|
|
+ List<DeptRespDTO> childDeptList = deptApi.getChildDeptList(deptByName.get(0).getId());
|
|
|
+ List<DeptRespDTO> projects = childDeptList.stream().filter(e -> deptByName.get(0).getId().equals(e.getParentId())).collect(Collectors.toList());
|
|
|
+ List<ImmutableMap<String, ? extends Serializable>> result = projects.stream().map(e -> {
|
|
|
+ List<DeptRespDTO> allSubclasses = findAllSubclasses(childDeptList, e.getId());
|
|
|
+ Set<Long> collect = allSubclasses.stream().map(DeptRespDTO::getId).collect(Collectors.toSet());
|
|
|
+ collect.add(e.getId());
|
|
|
+ Long l = iotDeviceMapper.selectByDept(collect);
|
|
|
+ return ImmutableMap.of("name", e.getName(), "value", l);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<DeptRespDTO> findAllSubclasses(List<DeptRespDTO> allNodes, Long parentId) {
|
|
|
+ List<DeptRespDTO> result = new ArrayList<>();
|
|
|
+
|
|
|
+ // 先找到直接子节点
|
|
|
+ for (DeptRespDTO node : allNodes) {
|
|
|
+ if (parentId.equals(node.getParentId())) {
|
|
|
+ result.add(node);
|
|
|
+ // 递归查找子节点的子节点,并添加到结果中
|
|
|
+ result.addAll(findAllSubclasses(allNodes, node.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
|