baoshiwei
2025-04-19 5d36e1f987ef21e44ded2e8a1d06c28094ec1e76
zhitan-admin/src/main/java/com/zhitan/web/controller/model/EnergyIndexController.java
@@ -9,17 +9,21 @@
import com.zhitan.common.utils.poi.ExcelUtil;
import com.zhitan.model.domain.EnergyIndex;
import com.zhitan.model.domain.EnergyIndexQuery;
import com.zhitan.model.domain.vo.ModelNodeIndexInfo;
import com.zhitan.model.service.IEnergyIndexService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
 * 指标信息Controller
@@ -122,47 +126,52 @@
  }
  /**
   * 删除指标信息
     * 删除采集指标信息
   */
  @PreAuthorize("@ss.hasPermi('energyindex:energyindex:remove')")
  @Log(title = "指标信息", businessType = BusinessType.DELETE)
  @DeleteMapping("/{nodeId}/{indexIds}")
  public AjaxResult remove(@PathVariable String nodeId, @PathVariable String[] indexIds) {
    List<EnergyIndex> energyIndexList = energyIndexService.getEnergyIndexByIds(
        Arrays.asList(indexIds));
    List<String> deleteIds = energyIndexList.stream()
        .filter(f -> StringUtils.isBlank(f.getMeterId()))
        .map(EnergyIndex::getIndexId)
        .collect(Collectors.toList());
    /**
     * 处理能源指标列表并生成需要移除的指标ID集合
     * 1. 过滤出meterId非空的能源指标对象
     * 2. 提取这些对象的indexId字段
     * 3. 将提取的指标ID收集到字符串集合中
     */
    List<String> removeLink = energyIndexList.stream()
        .filter(f -> StringUtils.isNotBlank(f.getMeterId()))
        .map(EnergyIndex::getIndexId)
        .collect(Collectors.toList());
    @DeleteMapping("/{indexIds}")
    public AjaxResult remove(@PathVariable String[] indexIds) {
    if (!removeLink.isEmpty()) {
      energyIndexService.removeNodeIndex(nodeId, removeLink);
        List<String> indexIdList = Arrays.asList(indexIds);
        if (ObjectUtils.isEmpty(indexIdList)) {
            return AjaxResult.success();
        }
        // 查询模型节点点位信息
        List<ModelNodeIndexInfo> modelNodeIndexInfoList = energyIndexService.getModelNodeIndexInfoListByIndexIds(indexIds);
        if (ObjectUtils.isNotEmpty(modelNodeIndexInfoList)) {
            ModelNodeIndexInfo modelNodeIndexInfo = modelNodeIndexInfoList.stream().findFirst().get();
            return AjaxResult.error("采集指标 " + modelNodeIndexInfo.getIndexName() + " 已被模型 " + modelNodeIndexInfo.getModelName() + " 关联,不能删除!");
    }
    if (!deleteIds.isEmpty()) {
      energyIndexService.deleteEnergyIndexByIds(nodeId, deleteIds.toArray(new String[0]));
    }
        energyIndexService.removeEnergyIndex(indexIdList);
    return AjaxResult.success();
  }
  /**
   * 新增通过id删除采集点接口
     * 删除统计指标信息
   */
  @PreAuthorize("@ss.hasPermi('energyindex:energyindex:remove')")
  @Log(title = "指标信息", businessType = BusinessType.DELETE)
  @DeleteMapping("/{indexId}")
  public AjaxResult deleteCollectIndex(@PathVariable String indexId) {
    return toAjax(energyIndexService.deleteByIndexId(indexId));
    @DeleteMapping("{nodeId}/{indexIds}")
    public AjaxResult remove(@PathVariable String nodeId, @PathVariable String[] indexIds) {
        List<String> indexIdList = Arrays.asList(indexIds);
        if (ObjectUtils.isEmpty(indexIdList)) {
            return AjaxResult.success();
        }
        // 查询模型节点点位信息
        List<ModelNodeIndexInfo> modelNodeIndexInfoList = energyIndexService.getModelNodeIndexInfoListByIndexIds(indexIds);
        if (ObjectUtils.isNotEmpty(modelNodeIndexInfoList)) {
            if(modelNodeIndexInfoList.size() > 1){
                return AjaxResult.error("该统计指标已被其他模型关联,不能删除!");
            }
        }
        energyIndexService.removeEnergyIndex(indexIdList);
        return AjaxResult.success();
  }
  @Log(title = "增加计量器具采集点", businessType = BusinessType.INSERT)