|
@@ -1,7 +1,6 @@
|
|
|
package com.ruoyi.ems.controller;
|
|
|
|
|
|
import com.huashe.common.domain.AjaxResult;
|
|
|
-import com.huashe.common.exception.BusinessException;
|
|
|
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.common.core.web.controller.BaseController;
|
|
|
import com.ruoyi.common.core.web.page.TableDataInfo;
|
|
@@ -9,14 +8,12 @@ import com.ruoyi.common.log.annotation.Log;
|
|
|
import com.ruoyi.common.log.enums.BusinessType;
|
|
|
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
|
|
import com.ruoyi.ems.domain.Area;
|
|
|
-import com.ruoyi.ems.domain.EmsDevice;
|
|
|
import com.ruoyi.ems.domain.MeterDevice;
|
|
|
-import com.ruoyi.ems.model.QueryDevice;
|
|
|
+import com.ruoyi.ems.model.TreeEntity;
|
|
|
import com.ruoyi.ems.service.IAreaService;
|
|
|
import com.ruoyi.ems.service.IMeterDeviceService;
|
|
|
-import com.ruoyi.ems.util.AreaUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -25,11 +22,14 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 计量设备Controller
|
|
@@ -59,34 +59,77 @@ public class MeterDeviceController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 递归查询 区域 下的设备(分页)
|
|
|
+ * 根据设施获取设备树结构
|
|
|
+ *
|
|
|
+ * @param parentCode 区域code
|
|
|
+ * @return 树结构
|
|
|
*/
|
|
|
- @RequiresPermissions("basecfg:device:list")
|
|
|
- @GetMapping("/listRecursionByArea")
|
|
|
- public TableDataInfo listRecursionByArea(QueryDevice queryDevice) {
|
|
|
- TableDataInfo tabInfo = null;
|
|
|
-
|
|
|
- try {
|
|
|
- if (StringUtils.isNotEmpty(queryDevice.getLocationRef())) {
|
|
|
- List<Area> areaTree = areaService.selectAreaTree(queryDevice.getLocationRef(), true);
|
|
|
- List<String> areaCodes = new ArrayList<>();
|
|
|
- areaCodes.add(queryDevice.getLocationRef());
|
|
|
- // 递归取出区域子节点code做查询条件(需要将子节点区域关联设备一并取出)
|
|
|
- AreaUtils.getCodeRecursion(areaTree, areaCodes);
|
|
|
- queryDevice.setAreaCodes(areaCodes);
|
|
|
+ @RequiresPermissions("basecfg:meterdevc:list")
|
|
|
+ @GetMapping("/getTreeByArea")
|
|
|
+ public AjaxResult getTreeByArea(
|
|
|
+ @RequestParam(name = "parentCode", required = false, defaultValue = "0") String parentCode,
|
|
|
+ @RequestParam(value = "meterCls", required = false) Integer meterCls,
|
|
|
+ @RequestParam(value = "colMode", required = false) Integer colMode) {
|
|
|
+ List<TreeEntity> retList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 查询区域树
|
|
|
+ List<Area> areas = areaService.selectAreaTree(parentCode, true);
|
|
|
+
|
|
|
+ // 查询设备列表
|
|
|
+ MeterDevice queryParam = new MeterDevice();
|
|
|
+ queryParam.setMeterCls(meterCls);
|
|
|
+ queryParam.setColMode(colMode);
|
|
|
+ List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(queryParam);
|
|
|
+ Map<String, List<MeterDevice>> groupMap = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(MeterDevice::getLocationRef, Collectors.toList()));
|
|
|
+
|
|
|
+ for (Area area : areas) {
|
|
|
+ List<TreeEntity> childList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (groupMap.containsKey(area.getAreaCode())) {
|
|
|
+ TreeEntity local = new TreeEntity();
|
|
|
+ local.setLabel("本级");
|
|
|
+ local.setChildren(convertToTreeEntity(groupMap.get(area.getAreaCode())));
|
|
|
+ childList.add(local);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当前层级小于最大层级时,递归处理子节点
|
|
|
+ if (CollectionUtils.isNotEmpty(area.getChildren())) {
|
|
|
+ List<?> childAreas = area.getChildren();
|
|
|
+ for (Object obj : childAreas) {
|
|
|
+ Area child = (Area) obj;
|
|
|
+ String childCode = child.getAreaCode();
|
|
|
+ TreeEntity local = new TreeEntity();
|
|
|
+ local.setLabel(child.getAreaName());
|
|
|
+
|
|
|
+ if (null != groupMap.get(childCode)) {
|
|
|
+ local.setChildren(convertToTreeEntity(groupMap.get(childCode)));
|
|
|
+ }
|
|
|
+
|
|
|
+ childList.add(local);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- startPage();
|
|
|
- List<MeterDevice> list = meterDeviceService.selectByAreaTree(queryDevice);
|
|
|
- tabInfo = getDataTable(list);
|
|
|
+ TreeEntity treeNode = new TreeEntity();
|
|
|
+ treeNode.setLabel(area.getAreaName());
|
|
|
+ treeNode.setChildren(childList);
|
|
|
+ retList.add(treeNode);
|
|
|
}
|
|
|
- catch (BusinessException e) {
|
|
|
- tabInfo = new TableDataInfo();
|
|
|
- tabInfo.setCode(e.getCode());
|
|
|
- tabInfo.setMsg(e.getMessage());
|
|
|
+
|
|
|
+ return success(retList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TreeEntity> convertToTreeEntity(List<MeterDevice> devList) {
|
|
|
+ List<TreeEntity> ret = new ArrayList<>();
|
|
|
+
|
|
|
+ for (MeterDevice dev : devList) {
|
|
|
+ TreeEntity entity = new TreeEntity();
|
|
|
+ entity.setId(dev.getDeviceCode());
|
|
|
+ entity.setLabel(dev.getDeviceName());
|
|
|
+ ret.add(entity);
|
|
|
}
|
|
|
|
|
|
- return tabInfo;
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
/**
|