app功能合并

This commit is contained in:
xy
2026-03-25 13:33:47 +08:00
parent fc7694a1db
commit 720afd42df
127 changed files with 5356 additions and 1346 deletions

View File

@@ -5,6 +5,8 @@ import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csdevice.api.fallback.CsDeviceUserClientFallbackFactory;
import com.njcn.csdevice.pojo.param.UserDevParam;
import com.njcn.csdevice.pojo.po.CsDeviceUserPO;
import com.njcn.csdevice.pojo.vo.DevUserVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -29,4 +31,11 @@ public interface CsDeviceUserFeignClient {
@PostMapping("/channelDevByUserId")
HttpResult<List<String>> channelDevByUserId(@RequestBody UserDevParam param);
@PostMapping("/queryUserById")
HttpResult<DevUserVO> queryUserById(@RequestParam("devId") String devId);
@PostMapping("/getList")
@ApiOperation("根据设备集合获取数据")
HttpResult<List<CsDeviceUserPO>> getList(@RequestBody UserDevParam param);
}

View File

@@ -35,6 +35,10 @@ public interface CsLedgerFeignClient {
@PostMapping("/queryDevDetail")
HttpResult<DevDetailDTO> queryDevDetail(@RequestParam("devId") String devId);
@PostMapping("/lineTree")
@ApiOperation("五层设备树(监测点层,根节点为治理设备和便携式设备)")
HttpResult<List<CsLedgerVO>> lineTree();
@PostMapping("/deviceTree")
@ApiOperation("三层设备树(装置层)")
HttpResult<List<CsLedgerVO>> getDeviceTree();

View File

@@ -1,8 +1,13 @@
package com.njcn.csdevice.api;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.api.fallback.CsLineClientFallbackFactory;
import com.njcn.csdevice.pojo.dto.CsLineDTO;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.LineDetailDataVO;
@@ -64,6 +69,9 @@ public interface CsLineFeignClient {
@PostMapping("/getAllLine")
HttpResult<List<String>> getAllLine();
@PostMapping("/getAllLineDetail")
HttpResult<List<CsLineDTO>> getAllLineDetail();
@PostMapping("/getOverLimitDataByIds")
HttpResult<List<Overlimit>> getOverLimitData(@RequestBody List<String> ids);

View File

@@ -0,0 +1,22 @@
package com.njcn.csdevice.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csdevice.api.fallback.ProcessFeignClientFallbackFactory;
import com.njcn.csdevice.pojo.po.CsUserPins;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.List;
/**
* @author xy
*/
@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/csUserPins", fallbackFactory = ProcessFeignClientFallbackFactory.class,contextId = "csUserPins")
public interface CsUserPinsFeignClient {
@PostMapping("/getPinToTopList")
HttpResult<List<CsUserPins>> getPinToTopList();
}

View File

@@ -0,0 +1,23 @@
package com.njcn.csdevice.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csdevice.api.fallback.AppProjectClientFallbackFactory;
import com.njcn.csdevice.pojo.param.CsEngineeringQueryParm;
import com.njcn.csdevice.pojo.vo.CsEngineeringVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* @author xy
*/
@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/engineering", fallbackFactory = AppProjectClientFallbackFactory.class,contextId = "engineering")
public interface EngineeringFeignClient {
@PostMapping("/queryEngineering")
HttpResult<List<CsEngineeringVO>> queryEngineering(@Validated @RequestBody CsEngineeringQueryParm csEngineeringQueryParm);
}

View File

@@ -6,6 +6,7 @@ import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
import com.njcn.csdevice.pojo.param.UserDevParam;
import com.njcn.csdevice.pojo.po.CsDeviceUserPO;
import com.njcn.csdevice.pojo.vo.DevUserVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -51,6 +52,18 @@ public class CsDeviceUserClientFallbackFactory implements FallbackFactory<CsDevi
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<DevUserVO> queryUserById(String devId) {
log.error("{}异常,降级处理,异常为:{}","获取设备主/子用户数据异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<CsDeviceUserPO>> getList(UserDevParam param) {
log.error("{}异常,降级处理,异常为:{}","根据设备集合获取数据异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -57,6 +57,12 @@ public class CsLedgerFeignClientFallbackFactory implements FallbackFactory<CsLed
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<CsLedgerVO>> lineTree() {
log.error("{}异常,降级处理,异常为:{}","查询监测点数数据异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<CsLedgerVO>> getDeviceTree() {
log.error("{}异常,降级处理,异常为:{}","查询设备树",cause.toString());

View File

@@ -4,6 +4,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.pojo.dto.CsLineDTO;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.LineDetailDataVO;
@@ -103,6 +104,12 @@ public class CsLineClientFallbackFactory implements FallbackFactory<CsLineFeignC
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<CsLineDTO>> getAllLineDetail() {
log.error("{}异常,降级处理,异常为:{}","获取系统中所有监测点id详情异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<Overlimit>> getOverLimitData(List<String> ids) {
log.error("{}异常,降级处理,异常为:{}","根据监测点id集合获取国标限值异常",cause.toString());

View File

@@ -0,0 +1,43 @@
package com.njcn.csdevice.api.fallback;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csdevice.api.CsUserPinsFeignClient;
import com.njcn.csdevice.pojo.po.CsUserPins;
import com.njcn.csdevice.utils.CsDeviceEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/4/10 20:09
*/
@Slf4j
@Component
public class CsUserPinsFeignClientFallbackFactory implements FallbackFactory<CsUserPinsFeignClient> {
@Override
public CsUserPinsFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
exceptionEnum = CsDeviceEnumUtil.getExceptionEnum(businessException.getResult());
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new CsUserPinsFeignClient() {
@Override
public HttpResult<List<CsUserPins>> getPinToTopList() {
log.error("{}异常,降级处理,异常为:{}","获取用户置顶设备(工程)数据异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -0,0 +1,38 @@
package com.njcn.csdevice.api.fallback;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csdevice.api.EngineeringFeignClient;
import com.njcn.csdevice.pojo.param.CsEngineeringQueryParm;
import com.njcn.csdevice.pojo.vo.CsEngineeringVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author xy
*/
@Slf4j
@Component
public class EngineeringClientFallbackFactory implements FallbackFactory<EngineeringFeignClient> {
@Override
public EngineeringFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new EngineeringFeignClient() {
@Override
public HttpResult<List<CsEngineeringVO>> queryEngineering(CsEngineeringQueryParm csEngineeringQueryParm) {
log.error("{}异常,降级处理,异常为:{}","查询工程列表接口异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -0,0 +1,28 @@
package com.njcn.csdevice.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @author xy
*/
@Data
public class CsUserPinsParam implements Serializable {
@ApiModelProperty("用户id")
@NotBlank(message = "用户id")
private String userId;
@ApiModelProperty("目标类型1-设备2-工程")
@NotNull(message = "目标类型1-设备2-工程")
private Integer targetType;
@ApiModelProperty("目标ID设备ID或工程ID")
@NotBlank(message = "目标ID设备ID或工程ID")
private String targetId;
}

View File

@@ -0,0 +1,148 @@
package com.njcn.csdevice.pojo.dto;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@NoArgsConstructor
public class CsLineDTO implements Serializable {
/**
* 监测点id
*/
private String lineId;
/**
* 装置id
*/
private String deviceId;
/**
* 装置id
*/
private String deviceType;
/**
* 监测点名称
*/
private String name;
/**
* 字典表:安装位置(负载侧,电网侧, 输出侧)
*/
private String position;
/**
* 数据集id
*/
private String dataSetId;
/**
* 模板id
*/
private String dataModelId;
/**
* 电压等级
*/
private Double volGrade;
/**
* PT变比
*/
private Double ptRatio;
/**
* PT2次变比
*/
private Double pt2Ratio;
/**
* CT变比
*/
private Double ctRatio;
/**
* CT2变比
*/
private Double ct2Ratio;
/**
* 状态(0删除 1正常)
*/
private Integer status;
/**
* 接线方式(0-星型 1-角型 2-V型)
*/
private Integer conType;
/**
* 逻辑子设备id(与模板对应)
*/
private Integer clDid;
/**
* 监测点统计间隔
*/
private Integer lineInterval;
/**
* 运行状态
*/
private Integer runStatus;
/**
* 监测点线路号
*/
private Integer lineNo;
/**
* 监测对象类型
*/
private String monitorObj;
/**
* 是否治理(0:未治理 1:已治理)
*/
private Integer govern;
private String monitorUser;
/**
* 短路容量
*/
private Double shortCircuitCapacity;
/**
* 设备容量
*/
private Double devCapacity;
/**
* 基准容量
*/
private Double basicCapacity;
/**
* 协议容量
*/
private Double protocolCapacity;
/**
* 治理报告文件路径
*/
private String reportFilePath;
/**
* 日志等级(NORMAL、DEBUG、WARN、ERROR)
*/
private String lineLogLevel;
/**
* 是否是主要监测点(0: 不是 1:是)
*/
private Integer isImportant;
}

View File

@@ -31,4 +31,10 @@ public class DevDetailDTO {
@ApiModelProperty(value = "设备名称")
private String equipmentName;
@ApiModelProperty(value = "设备通讯状态")
private Integer runStatus;
@ApiModelProperty(value = "设备MAC地址")
private String devMac;
}

View File

@@ -3,6 +3,8 @@ package com.njcn.csdevice.pojo.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* Description:
* Date: 2023/8/1 15:25【需求编号】
@@ -26,4 +28,29 @@ public class LineParamDTO {
@ApiModelProperty(value = "监测点id")
private String lineId;
@ApiModelProperty(value = "时间类型 0:日报 1:月报")
private Integer timeType;
@ApiModelProperty(value = "时间")
private String time;
@ApiModelProperty(value = "起始时间")
private String startTime;
@ApiModelProperty(value = "结束时间")
private String endTime;
@ApiModelProperty(value = "集合")
private List<String> list;
@Data
public static class DevParamDTO {
@ApiModelProperty(value = "时间")
private String time;
@ApiModelProperty(value = "设备id集合")
private List<String> devList;
}
}

View File

@@ -0,0 +1,44 @@
package com.njcn.csdevice.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.bo.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
/**
* <p>
* 用户置顶表
* </p>
*
* @author xy
* @since 2026-03-04
*/
@Getter
@Setter
@TableName("cs_user_pins")
public class CsUserPins extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
private String id;
/**
* 用户ID
*/
private String userId;
/**
* 目标类型1-设备2-工程
*/
private Integer targetType;
/**
* 目标ID设备ID或工程ID
*/
private String targetId;
}

View File

@@ -67,5 +67,6 @@ public class CsEngineeringVO extends BaseEntity {
@ApiModelProperty(value = "状态")
private String status;
@ApiModelProperty(value = "排序")
private Integer sort;
}

View File

@@ -69,6 +69,9 @@ public class CsLedgerVO implements Serializable {
@ApiModelProperty(name = "process",value = "流程状态")
private Integer process;
@ApiModelProperty(name = "isTop",value = "是否置顶,默认不置顶")
private Integer isTop = 0;
@ApiModelProperty(name = "children",value = "子节点")
private List<CsLedgerVO> children = new ArrayList<>();

View File

@@ -0,0 +1,41 @@
package com.njcn.csdevice.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2026/3/5
*/
@Data
public class EngineeringHomePageVO implements Serializable {
@ApiModelProperty(name = "engineeringId",value = "工程id")
private String engineeringId;
@ApiModelProperty(name = "engineeringName",value = "工程名称")
private String engineeringName;
@ApiModelProperty(name = "devTotal",value = "设备总数")
private Integer devTotal;
@ApiModelProperty(name = "onlineDevTotal",value = "在线设备数")
private Integer onlineDevTotal;
@ApiModelProperty(name = "offlineDevTotal",value = "离线设备数")
private Integer offlineDevTotal;
@ApiModelProperty(name = "alarmTotal",value = "告警数量(未读)")
private Integer alarmTotal;
@ApiModelProperty(name = "isTop",value = "是否置顶 0:未置顶 1:已置顶")
private Integer isTop = 0;
@ApiModelProperty(name = "sort",value = "排序")
private Integer sort;
}

View File

@@ -1,8 +1,11 @@
package com.njcn.csdevice.pojo.vo;
import com.njcn.csdevice.pojo.po.CsLinePO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
*
* Description:
@@ -54,4 +57,16 @@ public class ProjectEquipmentVO {
@ApiModelProperty(value = "设备nDid")
private String nDid;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "是否置顶(0:未置顶 1:置顶),默认是0")
private Integer isTop = 0;
@ApiModelProperty(value = "设备类型(监测设备:DEV_CLD 治理设备:Direct_Connected_Device)")
private String devType;
@ApiModelProperty(value = "监测点集合")
private List<CsLinePO> lineList;
}

View File

@@ -161,4 +161,14 @@ public class DeviceUserController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getList")
@ApiOperation("根据设备集合获取数据")
@ApiImplicitParam(name = "param", value = "参数", required = true)
public HttpResult<List<CsDeviceUserPO>> getList(@RequestBody UserDevParam param){
String methodDescribe = getMethodDescribe("getList");
List<CsDeviceUserPO> list = csDeviceUserPOService.getList(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
}

View File

@@ -54,18 +54,20 @@ public class CsLedgerController extends BaseController {
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/lineTree")
@ApiOperation("五层设备树(监测点层,根节点为治理设备和便携式设备)")
public HttpResult<List<CsLedgerVO>> lineTree(){
@ApiImplicitParam(name = "type", value = "台账树类型")
public HttpResult<List<CsLedgerVO>> lineTree(@RequestParam(required = false) @Validated String type){
String methodDescribe = getMethodDescribe("lineTree");
List<CsLedgerVO> list = csLedgerService.getLineTree();
List<CsLedgerVO> list = csLedgerService.getLineTree(type);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/deviceTree")
@ApiOperation("四层设备树(装置层,根节点为治理设备和便携式设备)")
public HttpResult<List<CsLedgerVO>> getDeviceTree(){
@ApiImplicitParam(name = "type", value = "台账树类型")
public HttpResult<List<CsLedgerVO>> getDeviceTree(@RequestParam(required = false) @Validated String type){
String methodDescribe = getMethodDescribe("getDeviceTree");
List<CsLedgerVO> list = csLedgerService.getDeviceTree();
List<CsLedgerVO> list = csLedgerService.getDeviceTree(type);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}

View File

@@ -7,6 +7,7 @@ import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.pojo.dto.CsLineDTO;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.LineDetailDataVO;
@@ -254,6 +255,15 @@ public class CslineController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getAllLineDetail")
@ApiOperation("获取所有监测点id详情")
public HttpResult<List<CsLineDTO>> getAllLineDetail(){
String methodDescribe = getMethodDescribe("getAllLineDetail");
List<CsLineDTO> list = csLinePOService.getAllLineDetail();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@GetMapping("/getSimpleLine")
@ApiOperation("查询登录用户拥有的监测点台账")

View File

@@ -0,0 +1,61 @@
package com.njcn.csdevice.controller.project;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.param.CsUserPinsParam;
import com.njcn.csdevice.pojo.po.CsUserPins;
import com.njcn.csdevice.service.ICsUserPinsService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* 用户置顶表 前端控制器
* </p>
*
* @author xy
* @since 2026-03-04
*/
@Slf4j
@RestController
@RequestMapping("/csUserPins")
@Api(tags = "置顶设备(工程)")
@AllArgsConstructor
public class CsUserPinsController extends BaseController {
private final ICsUserPinsService csUserPinsService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/engineeringPinToTop")
@ApiOperation("用户置顶工程(取消置顶)")
public HttpResult<Boolean> engineeringPinToTop(@Validated @RequestBody CsUserPinsParam param){
String methodDescribe = getMethodDescribe("engineeringPinToTop");
Boolean result = csUserPinsService.engineeringPinToTop(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getPinToTopList")
@ApiOperation("获取用户置顶设备(工程)")
public HttpResult<List<CsUserPins>> getPinToTopList(){
String methodDescribe = getMethodDescribe("getPinToTopList");
List<CsUserPins> result = csUserPinsService.getPinToTopList();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -103,4 +103,5 @@ public class EngineeringController extends BaseController {
List<CsEngineeringPO> result = csEngineeringService.getUnlinkedEngineering(userId);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -1,6 +1,7 @@
package com.njcn.csdevice.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.csdevice.pojo.dto.CsLineDTO;
import com.njcn.csdevice.pojo.po.CsLinePO;
import org.apache.ibatis.annotations.Param;
@@ -21,4 +22,6 @@ public interface CsLinePOMapper extends BaseMapper<CsLinePO> {
Map<String,String> getCustomDetailByLineId(@Param("lineId")String lineId);
List<CsLineDTO> findLineList();
}

View File

@@ -0,0 +1,16 @@
package com.njcn.csdevice.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.csdevice.pojo.po.CsUserPins;
/**
* <p>
* 用户置顶表 Mapper 接口
* </p>
*
* @author xy
* @since 2026-03-04
*/
public interface CsUserPinsMapper extends BaseMapper<CsUserPins> {
}

View File

@@ -41,7 +41,9 @@
c.create_time createTime,
c.run_status,
c.mac mac,
c.process process
c.process process,
c.sort sort,
c.dev_type devType
FROM
(select * from cs_ledger where LEVEL = 0 and State =1
) a,

View File

@@ -53,4 +53,15 @@
WHERE
line.line_id = #{lineId}
</select>
<select id="findLineList" resultType="com.njcn.csdevice.pojo.dto.CsLineDTO">
SELECT
t1.*,
t2.dev_type deviceType
FROM
cs_line t1
LEFT JOIN cs_equipment_delivery t2 ON t1.device_id = t2.id
WHERE
t1.`status` = 1
</select>
</mapper>

View File

@@ -53,4 +53,6 @@ public interface CsDeviceUserPOService extends IService<CsDeviceUserPO>{
List<String> findDevByUserId(String userId);
void channelDevByUserId(UserDevParam param);
List<CsDeviceUserPO> getList(UserDevParam param);
}

View File

@@ -2,6 +2,7 @@ package com.njcn.csdevice.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csdevice.pojo.dto.CsLineDTO;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.LineDetailDataVO;
@@ -81,6 +82,8 @@ public interface CsLinePOService extends IService<CsLinePO>{
List<String> getAllLine();
List<CsLineDTO> getAllLineDetail();
List<CsLinePO> getSimpleLine();
List<CsLinePO> getLineBySensitiveUser(List<String> list);

View File

@@ -29,13 +29,13 @@ public interface ICsLedgerService extends IService<CsLedger> {
* 获取终端台账树
* @return
*/
List<CsLedgerVO> getLineTree();
List<CsLedgerVO> getLineTree(String type);
/**
* 终端三层树
* @return
*/
List<CsLedgerVO> getDeviceTree();
List<CsLedgerVO> getDeviceTree(String type);
/**
* 新增台账数据

View File

@@ -0,0 +1,35 @@
package com.njcn.csdevice.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csdevice.param.CsUserPinsParam;
import com.njcn.csdevice.pojo.po.CsUserPins;
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import java.util.List;
/**
* <p>
* 用户置顶表 服务类
* </p>
*
* @author xy
* @since 2026-03-04
*/
public interface ICsUserPinsService extends IService<CsUserPins> {
boolean engineeringPinToTop(CsUserPinsParam param);
List<CsUserPins> getPinToTopList();
/**
* 针对台账树中存在置顶的数据进行排序
*
* @param list 置顶数据
* @param tree 台账树
* @param level 树的层级
* 如果第一层不是工程并且是5层树level = 5 5层树层级必须是 0:设备类型 1:工程 2:项目 3:设备 4:监测点
* 如果第一层是工程level = 4 4层树层级必须是 0:工程 1:项目 2:设备 3:监测点其余层级的树也可以使用level = 4只要是工程、项目、设备、监测点这样的结构就行
*/
void channelTree(List<CsUserPins> list, List<CsLedgerVO> tree, Integer level);
}

View File

@@ -17,6 +17,7 @@ import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import com.njcn.csdevice.pojo.vo.DevCountVO;
import com.njcn.csdevice.pojo.vo.DevUserVO;
import com.njcn.csdevice.service.*;
import com.njcn.csdevice.utils.StringUtil;
import com.njcn.csharmonic.api.EventUserFeignClient;
import com.njcn.csharmonic.param.CsEventUserQueryParam;
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
@@ -28,6 +29,7 @@ import com.njcn.user.enums.AppRoleEnum;
import com.njcn.user.pojo.po.User;
import com.njcn.web.utils.RequestUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -156,7 +158,7 @@ public class CsDeviceUserPOServiceImpl extends ServiceImpl<CsDeviceUserPOMapper,
devCountVO.setEningerCount(roleengineer.size());
}
List<CsLedgerVO> deviceTree = iCsLedgerService.getDeviceTree();
List<CsLedgerVO> deviceTree = iCsLedgerService.getDeviceTree(null);
//由于多加了一程便携式设备
List<String> collect1 = deviceTree.stream()
.map(CsLedgerVO::getChildren).flatMap(Collection::stream)
@@ -406,7 +408,12 @@ public class CsDeviceUserPOServiceImpl extends ServiceImpl<CsDeviceUserPOMapper,
@Override
public List<String> findDevByUserId(String userId) {
List<String> result = new ArrayList<>();
List<CsDeviceUserPO> list = this.lambdaQuery().eq(CsDeviceUserPO::getPrimaryUserId,userId).list();
LambdaQueryWrapper<CsDeviceUserPO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.and(wrapper ->
wrapper.eq(CsDeviceUserPO::getPrimaryUserId, userId)
.or()
.eq(CsDeviceUserPO::getSubUserId, userId));
List<CsDeviceUserPO> list = this.list(queryWrapper);
if (CollectionUtil.isNotEmpty(list)){
result = list.stream().map(CsDeviceUserPO::getDeviceId).collect(Collectors.toList());
}
@@ -416,8 +423,26 @@ public class CsDeviceUserPOServiceImpl extends ServiceImpl<CsDeviceUserPOMapper,
@Override
public void channelDevByUserId(UserDevParam param) {
LambdaQueryWrapper<CsDeviceUserPO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CsDeviceUserPO::getPrimaryUserId,param.getUserId())
.in(CsDeviceUserPO::getDeviceId,param.getList());
queryWrapper.and(wrapper ->
wrapper.eq(CsDeviceUserPO::getPrimaryUserId, param.getUserId())
.or()
.eq(CsDeviceUserPO::getSubUserId, param.getUserId())
).in(CsDeviceUserPO::getDeviceId, param.getList());
this.remove(queryWrapper);
}
@Override
public List<CsDeviceUserPO> getList(UserDevParam param) {
LambdaQueryWrapper<CsDeviceUserPO> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotBlank(param.getUserId())) {
queryWrapper.and(wrapper ->
wrapper.eq(CsDeviceUserPO::getPrimaryUserId, param.getUserId())
.or()
.eq(CsDeviceUserPO::getSubUserId, param.getUserId())
);
}
queryWrapper.in(CsDeviceUserPO::getDeviceId, param.getList())
.eq(CsDeviceUserPO::getStatus, "1");
return this.list(queryWrapper);
}
}

View File

@@ -165,7 +165,7 @@ public class CsEngineeringServiceImpl extends ServiceImpl<CsEngineeringMapper, C
queryWrapper.eq (StringUtils.isNotBlank (csEngineeringQueryParm.getProvince ()),"province",csEngineeringQueryParm.getProvince ()).
eq (StringUtils.isNotBlank (csEngineeringQueryParm.getCity ()),"city",csEngineeringQueryParm.getCity ()).
eq ("status","1" ).
like (StringUtils.isNotBlank (csEngineeringQueryParm.getName ()),"name",csEngineeringQueryParm.getName ()).orderByDesc("create_time");
like (StringUtils.isNotBlank (csEngineeringQueryParm.getName ()),"name",csEngineeringQueryParm.getName ()).orderByAsc("sort");
List<CsEngineeringPO> csEngineeringPOS = this.getBaseMapper ( ).selectList (queryWrapper);
csEngineeringVOList = csEngineeringPOS.stream ().map (temp->{
CsEngineeringVO vo = new CsEngineeringVO();
@@ -297,7 +297,6 @@ public class CsEngineeringServiceImpl extends ServiceImpl<CsEngineeringMapper, C
return this.update(queryWrapper);
}
public String getAreaById(String id){
String areaName =redisUtil.getStringByKey (id);

View File

@@ -48,7 +48,6 @@ import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.DictTreeFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.enums.DicTreeEnum;
import com.njcn.system.pojo.po.SysDicTreePO;
import com.njcn.system.pojo.vo.DictTreeVO;
import com.njcn.user.enums.AppRoleEnum;
@@ -107,6 +106,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
private final CsLedgerMapper csLedgerMapper;
private final CsTerminalLogsMapper csTerminalLogsMapper;
private final ICsCommunicateService csCommunicateService;
private final ICsUserPinsService csUserPinsService;
@Override
public void refreshDeviceDataCache() {
@@ -158,7 +158,11 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
csEquipmentProcess.setStatus (1);
csEquipmentProcessPOService.save(csEquipmentProcess);
result = this.save (csEquipmentDeliveryPo);
if (result) {
//谁新建的设备,则认为是该设备的主用户,新建用户设备关系表数据
boolean addUser = csDeviceUserPOService.add(csEquipmentDeliveryPo.getId());
if (result && addUser) {
refreshDeviceDataCache();
}
return csEquipmentDeliveryPo;
@@ -232,9 +236,45 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
return returnpage;
}
Page<ProjectEquipmentVO> list = this.baseMapper.queryProjectEquipmentVO(returnpage,projectEquipmentQueryParm,device);
list.getRecords().stream().forEach(temp->{
//根据设备id获取监测点id集合
List<CsLinePO> lineIds = csLinePOService.getLineByDev(device);
list.getRecords().forEach(temp->{
temp.setIsPrimaryUser(csDeviceUserPOService.isPrimaryUser(temp.getEquipmentId()));
//获取设备类型
SysDicTreePO po = dictTreeFeignClient.queryById(temp.getDevType()).getData();
temp.setDevType(po.getCode());
temp.setLineList(lineIds.stream().filter(line -> line.getDevId().equals(temp.getEquipmentId())).sorted(Comparator.comparing(CsLinePO::getLineId)).collect(Collectors.toList()));
});
List<ProjectEquipmentVO> recordList = list.getRecords();
//获取用户置顶的设备
List<CsUserPins> topList = csUserPinsService.getPinToTopList();
List<String> targetIdList = topList.stream()
.filter(item -> Objects.equals(item.getTargetType(), 1))
.map(CsUserPins::getTargetId)
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(targetIdList)) {
List<ProjectEquipmentVO> matchedList = new ArrayList<>();
List<ProjectEquipmentVO> unmatchedList = new ArrayList<>();
for (ProjectEquipmentVO node : recordList) {
if (targetIdList.contains(node.getEquipmentId())) {
node.setIsTop(1);
matchedList.add(node);
} else {
unmatchedList.add(node);
}
}
// 根据 targetIdList 的顺序对匹配的节点进行排序
matchedList.sort(Comparator.comparingInt(node -> targetIdList.indexOf(node.getEquipmentId())));
// 未匹配的节点按照原有的 sort 字段排序,处理 null 值情况
unmatchedList.sort(Comparator.comparing(node -> node.getSort() != null ? node.getSort() : Integer.MAX_VALUE));
// 清空原列表并添加排序后的数据
recordList.clear();
recordList.addAll(matchedList);
recordList.addAll(unmatchedList);
list.setRecords(recordList);
}
return list;
}
@@ -385,7 +425,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
dataSet = csDataSetService.findDataSetByModelId(modelId,2);
}
setDataSetValues(csEquipmentDeliveryPo, dataSet, dataSetList, type, deviceManagerVo);
} else if(Objects.equals(devTypeCode, DicDataEnum.PORTABLE.getCode()) || Objects.equals(devTypeCode, DicDataEnum.DEV_CLD.getCode())){
} else if(Objects.equals(devTypeCode, DicDataEnum.PORTABLE.getCode())){
List<CsDataSet> dataSet = new ArrayList<>();
List<CsDevModelRelationPO> modelId = csDevModelRelationService.findModelByDevId(deviceId);
if (CollUtil.isNotEmpty(modelId)){
@@ -394,6 +434,15 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
}
setDataSetValues(csEquipmentDeliveryPo, dataSet, dataSetList, type, deviceManagerVo);
}
} else if(Objects.equals(devTypeCode, DicDataEnum.DEV_CLD.getCode())){
List<CsDataSet> dataSet = new ArrayList<>();
List<CsDevModelRelationPO> modelId = csDevModelRelationService.findModelByDevId(deviceId);
if (CollUtil.isNotEmpty(modelId)){
for (CsDevModelRelationPO item : modelId) {
dataSet.addAll(csDataSetService.findDataSetByModelId(item.getModelId(),1));
}
setDataSetValues(csEquipmentDeliveryPo, dataSet, dataSetList, type, deviceManagerVo);
}
}
}
return deviceManagerVo;
@@ -733,9 +782,9 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
boolean result = false;
//获取装置id
CsEquipmentDeliveryPO po = findDevByNDid(nDid);
//设备型
String code = dictTreeFeignClient.queryById(po.getDevModel()).getData().getCode();
if (Objects.equals(DicTreeEnum.PQ_COM.getCode(),code)) {
//设备
String code = dictTreeFeignClient.queryById(po.getDevType()).getData().getCode();
if (Objects.equals(DicDataEnum.DEV_CLD.getCode(),code) || Objects.equals(DicDataEnum.CONNECT_DEV.getCode(),code)) {
result = true;
}
return result;
@@ -751,10 +800,11 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
@Transactional(rollbackFor = Exception.class)
public CsEquipmentDeliveryPO saveCld(CsEquipmentDeliveryAddParm param) {
boolean result;
CsEquipmentDeliveryPO one = this.lambdaQuery().eq(CsEquipmentDeliveryPO::getName, param.getName()).ne(CsEquipmentDeliveryPO::getRunStatus, 0).one();
if(Objects.nonNull (one)){
throw new BusinessException ("设备名称不能重复");
}
//设备名称可以重复
//CsEquipmentDeliveryPO one = this.lambdaQuery().eq(CsEquipmentDeliveryPO::getName, param.getName()).ne(CsEquipmentDeliveryPO::getRunStatus, 0).one();
//if(Objects.nonNull (one)){
// throw new BusinessException ("设备名称不能重复");
//}
StringUtil.containsSpecialCharacters(param.getNdid());
CsEquipmentDeliveryPO po = this.queryEquipmentPOByndid (param.getNdid());
if(!Objects.isNull (po)){
@@ -800,7 +850,10 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
csLedger.setSort(0);
int addLedger = csLedgerMapper.insert(csLedger);
if (result && ObjectUtil.isNotNull(relation) && addLedger > 0) {
//谁新建的设备,则认为是该设备的主用户,新建用户设备关系表数据
boolean addUser = csDeviceUserPOService.add(csEquipmentDeliveryPo.getId());
if (result && ObjectUtil.isNotNull(relation) && addLedger > 0 && addUser) {
refreshDeviceDataCache();
}
return csEquipmentDeliveryPo;
@@ -1037,6 +1090,9 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
return result.stream()
.filter(data -> idSet.contains(data.getId()))
.collect(Collectors.toList());
} else {
result.clear();
return result;
}
}
return result;

View File

@@ -21,7 +21,7 @@ import com.njcn.csdevice.pojo.po.*;
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import com.njcn.csdevice.service.*;
import com.njcn.csharmonic.api.PqSensitiveUserFeignClient;
import com.njcn.csharmonic.pojo.po.PqSensitiveUser;
import com.njcn.device.biz.pojo.po.PqSensitiveUser;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.AreaFeignClient;
import com.njcn.system.api.DictTreeFeignClient;
@@ -67,12 +67,12 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
private final CsDeviceUserPOMapper csDeviceUserPOMapper;
private final PqSensitiveUserFeignClient pqSensitiveUserFeignClient;
private final UserFeignClient userFeignClient;
private final ICsUserPinsService csUserPinsService;
@Override
public List<CsLedgerVO> getLedgerTree() {
List<CsLedgerVO> list = new ArrayList<>();
List<CsLedgerVO> engineeringList = getLineTree();
List<CsLedgerVO> engineeringList = getLineTree(null);
CsLedgerVO vo = new CsLedgerVO();
vo.setId("9999999");
vo.setLevel(0);
@@ -85,7 +85,7 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
}
@Override
public List<CsLedgerVO> getLineTree() {
public List<CsLedgerVO> getLineTree(String type) {
List<CsLedgerVO> engineeringList;
List<CsLedgerVO> allList = this.baseMapper.getAll();
/*获取用户工程,设备信息过滤*/
@@ -267,18 +267,131 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
cld.setChildren(engineeringList2);
List<CsLedgerVO> tree = new ArrayList<>();
if (CollUtil.isNotEmpty(portables)) {
tree.add(portable);
}
if (CollUtil.isNotEmpty(deviceList)) {
tree.add(government);
}
if (CollUtil.isNotEmpty(cldDeviceList)) {
tree.add(cld);
//获取置顶的工程
List<CsUserPins> list = csUserPinsService.getPinToTopList();
if (Objects.equals(type,"engineering")) {
Map<String, CsLedgerVO> engineeringMap = new HashMap<>();
engineeringList1.forEach(eng -> {
CsLedgerVO existingEng = engineeringMap.get(eng.getId());
if (existingEng == null) {
engineeringMap.put(eng.getId(), eng);
} else {
List<CsLedgerVO> mergedChildren = mergeProjectList(existingEng.getChildren(), eng.getChildren());
existingEng.setChildren(mergedChildren);
}
});
engineeringList2.forEach(eng -> {
CsLedgerVO existingEng = engineeringMap.get(eng.getId());
if (existingEng == null) {
engineeringMap.put(eng.getId(), eng);
} else {
List<CsLedgerVO> mergedChildren = mergeProjectList(existingEng.getChildren(), eng.getChildren());
existingEng.setChildren(mergedChildren);
}
});
tree.addAll(new ArrayList<>(engineeringMap.values()));
String id = IdUtil.simpleUUID();
CsLedgerVO portable1 = new CsLedgerVO();
portable1.setLevel(0);
portable1.setName("便携式工程");
portable1.setPid("0");
portable1.setId(id);
CsLedgerVO portable2 = new CsLedgerVO();
portable2.setLevel(1);
portable2.setName("便携式项目");
portable2.setPid(id);
portable2.setId(IdUtil.simpleUUID());
portable2.setChildren(portables);
portable1.setChildren(Collections.singletonList(portable2));
tree.add(portable1);
if (CollectionUtil.isNotEmpty(list)) {
csUserPinsService.channelTree(list, tree, 4);
}
} else {
//按设备类型统计
if (CollUtil.isNotEmpty(portables)) {
tree.add(portable);
}
if (CollUtil.isNotEmpty(deviceList)) {
tree.add(government);
}
if (CollUtil.isNotEmpty(cldDeviceList)) {
tree.add(cld);
}
if (CollectionUtil.isNotEmpty(list)) {
csUserPinsService.channelTree(list, tree, 5);
}
}
return tree;
}
/**
* 合并两个项目列表,根据项目 ID 去重并合并子节点
*/
private List<CsLedgerVO> mergeProjectList(List<CsLedgerVO> list1, List<CsLedgerVO> list2) {
if (CollectionUtil.isEmpty(list1)) {
return list2 != null ? new ArrayList<>(list2) : new ArrayList<>();
}
if (CollectionUtil.isEmpty(list2)) {
return new ArrayList<>(list1);
}
Map<String, CsLedgerVO> projectMap = new HashMap<>();
list1.forEach(project -> {
projectMap.put(project.getId(), cloneProject(project));
});
list2.forEach(project -> {
CsLedgerVO existingProject = projectMap.get(project.getId());
if (existingProject == null) {
projectMap.put(project.getId(), cloneProject(project));
} else {
List<CsLedgerVO> mergedDevices = new ArrayList<>();
if (existingProject.getChildren() != null) {
mergedDevices.addAll(existingProject.getChildren());
}
if (project.getChildren() != null) {
mergedDevices.addAll(project.getChildren());
}
existingProject.setChildren(mergedDevices);
}
});
return new ArrayList<>(projectMap.values());
}
/**
* 克隆项目对象,避免引用问题
*/
private CsLedgerVO cloneProject(CsLedgerVO project) {
CsLedgerVO cloned = new CsLedgerVO();
cloned.setId(project.getId());
cloned.setPid(project.getPid());
cloned.setLevel(project.getLevel());
cloned.setName(project.getName());
cloned.setType(project.getType());
cloned.setComFlag(project.getComFlag());
cloned.setNDId(project.getNDId());
cloned.setProcess(project.getProcess());
cloned.setLineType(project.getLineType());
cloned.setConType(project.getConType());
cloned.setSort(project.getSort());
if (project.getChildren() != null) {
cloned.setChildren(new ArrayList<>(project.getChildren()));
}
return cloned;
}
//剔除未接入的设备(根据status判断不太稳,所有这里直接判断该设备有没有对应的模板指标)
private void checkDevSetData(List<CsLedgerVO> ledgerVOS) {
Iterator<CsLedgerVO> iterator = ledgerVOS.iterator();
@@ -309,7 +422,7 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
@Override
public List<CsLedgerVO> getDeviceTree() {
public List<CsLedgerVO> getDeviceTree(String type) {
List<CsLedgerVO> engineeringList;
List<CsLedgerVO> allList = this.baseMapper.getAll();
/*获取用户工程,设备信息过滤*/
@@ -471,14 +584,69 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
cld.setChildren(engineeringList2);
List<CsLedgerVO> tree = new ArrayList<>();
if (CollUtil.isNotEmpty(portables)) {
tree.add(portable);
List<CsUserPins> list = csUserPinsService.getPinToTopList();
if (Objects.equals(type,"engineering")) {
Map<String, CsLedgerVO> engineeringMap = new HashMap<>();
engineeringList1.forEach(eng -> {
CsLedgerVO existingEng = engineeringMap.get(eng.getId());
if (existingEng == null) {
engineeringMap.put(eng.getId(), eng);
} else {
List<CsLedgerVO> mergedChildren = mergeProjectList(existingEng.getChildren(), eng.getChildren());
existingEng.setChildren(mergedChildren);
}
});
engineeringList2.forEach(eng -> {
CsLedgerVO existingEng = engineeringMap.get(eng.getId());
if (existingEng == null) {
engineeringMap.put(eng.getId(), eng);
} else {
List<CsLedgerVO> mergedChildren = mergeProjectList(existingEng.getChildren(), eng.getChildren());
existingEng.setChildren(mergedChildren);
}
});
tree.addAll(new ArrayList<>(engineeringMap.values()));
String id = IdUtil.simpleUUID();
CsLedgerVO portable1 = new CsLedgerVO();
portable1.setLevel(0);
portable1.setName("便携式工程");
portable1.setPid("0");
portable1.setId(id);
CsLedgerVO portable2 = new CsLedgerVO();
portable2.setLevel(1);
portable2.setName("便携式项目");
portable2.setPid(id);
portable2.setId(IdUtil.simpleUUID());
portable2.setChildren(portables);
List<CsLedgerVO> portable2List = new ArrayList<>();
portable2List.add(portable2);
portable1.setChildren(portable2List);
tree.add(portable1);
if (CollectionUtil.isNotEmpty(list)) {
csUserPinsService.channelTree(list, tree, 4);
}
} else {
//按设备类型统计
if (CollUtil.isNotEmpty(portables)) {
tree.add(portable);
}
if (CollUtil.isNotEmpty(deviceList)) {
tree.add(government);
}
if (CollUtil.isNotEmpty(cldDevList)) {
tree.add(cld);
}
}
if (CollUtil.isNotEmpty(deviceList)) {
tree.add(government);
}
if (CollUtil.isNotEmpty(cldDevList)) {
tree.add(cld);
if (CollectionUtil.isNotEmpty(list)) {
csUserPinsService.channelTree(list, tree, 5);
}
return tree;
}
@@ -575,10 +743,14 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
public DevDetailDTO queryDevDetail(String devId) {
DevDetailDTO device = new DevDetailDTO();
CsLedger dev = this.findDataById(devId);
//获取设备mac
CsEquipmentDeliveryPO po = csEquipmentDeliveryMapper.selectById(devId);
//如果是便携式设备pid为0,项目,工程都设置为/
if (Objects.equals(dev.getPid(), "0")) {
device.setEquipmentName(dev.getName());
device.setEquipmentId(devId);
device.setDevMac(po.getMac());
device.setProjectId("/");
device.setProjectName("/");
device.setEngineeringid("/");
@@ -586,11 +758,11 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
} else {
device.setEquipmentName(dev.getName());
device.setEquipmentId(devId);
device.setDevMac(po.getMac());
CsLedger project = this.findDataById(dev.getPid());
if (ObjectUtil.isNotNull(project)) {
device.setProjectId(project.getId());
device.setProjectName(project.getName());
CsLedger engineer = this.findDataById(project.getPid());
if (ObjectUtil.isNotNull(engineer)) {
device.setEngineeringid(engineer.getId());
@@ -972,100 +1144,210 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
@Override
public CsLedgerVO cldTree() {
List<CsLedgerVO> engineerTree = new ArrayList<>();
List<CsLedgerVO> projectTree = new ArrayList<>();
List<CsLedgerVO> deviceTree = new ArrayList<>();
List<CsLedgerVO> lineTree = new ArrayList<>();
List<CsLedgerVO> allList = this.baseMapper.getAll();
if (CollectionUtil.isNotEmpty(allList)) {
//工程集合
List<CsLedgerVO> tree1 = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.ENGINEERING_LEVEL.getCode())).collect(Collectors.toList());
//项目集合
List<CsLedgerVO> tree2 = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.PROJECT_LEVEL.getCode())).collect(Collectors.toList());
//设备集合
List<CsLedgerVO> tree3 = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.DEVICE_LEVEL.getCode())).collect(Collectors.toList());
//监测点集合
List<CsLedgerVO> tree4 = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.LINE_LEVEL.getCode())).collect(Collectors.toList());
if (CollectionUtil.isEmpty(allList)) {
CsLedgerVO government = new CsLedgerVO();
government.setLevel(0);
government.setName(DataParam.cldDev);
government.setPid("0");
government.setId(IdUtil.simpleUUID());
government.setChildren(new ArrayList<>());
return government;
}
//筛选出云前置设备
if (CollectionUtil.isNotEmpty(tree3)) {
Set<String> list1 = new HashSet<>();
List<String> devList = tree3.stream().map(CsLedgerVO::getId).collect(Collectors.toList());
List<CsEquipmentDeliveryPO> devs = csEquipmentDeliveryMapper.selectBatchIds(devList);
Map<String, CsEquipmentDeliveryPO> devsMap = devs.stream().collect(Collectors.toMap(CsEquipmentDeliveryPO::getId, Function.identity()));
DictTreeVO vo1 = dictTreeFeignClient.queryByCode(DicDataEnum.DEV_CLD.getCode()).getData();
DictTreeVO cldDict = dictTreeFeignClient.queryByCode(DicDataEnum.DEV_CLD.getCode()).getData();
String cldDevTypeId = cldDict.getId();
//list1是 cld设备
devs.forEach(item -> {
if (item.getDevType().equals(vo1.getId())) {
list1.add(item.getId());
}
});
//list2是 非cld设备
Set<String> list2 = devList.stream().filter(item -> !list1.contains(item)).collect(Collectors.toSet());
List<CsLedgerVO> tree5 = tree3.stream().filter(vo -> list2.contains(vo.getId())).collect(Collectors.toList());
Set<String> list3 = tree5.stream().map(CsLedgerVO::getPid).collect(Collectors.toSet());
projectTree = tree2.stream().filter(vo -> !list3.contains(vo.getId())).collect(Collectors.toList());
List<CsLedgerVO> engineeringList = allList.stream()
.filter(item -> item.getLevel().equals(LineBaseEnum.ENGINEERING_LEVEL.getCode()))
.collect(Collectors.toList());
List<CsLedgerVO> tree6 = tree2.stream().filter(vo -> list3.contains(vo.getId())).collect(Collectors.toList());
Set<String> proList = tree6.stream().map(CsLedgerVO::getPid).collect(Collectors.toSet());
engineerTree = tree1.stream().filter(vo -> !proList.contains(vo.getId())).collect(Collectors.toList());
List<CsLedgerVO> projectList = allList.stream()
.filter(item -> item.getLevel().equals(LineBaseEnum.PROJECT_LEVEL.getCode()))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(list1)) {
deviceTree = tree3.stream()
.filter(vo -> list1.contains(vo.getId()))
.peek(item -> {
CsEquipmentDeliveryPO dev = devsMap.get(item.getId());
if (dev != null) {
item.setComFlag(dev.getRunStatus());
}
})
.collect(Collectors.toList());
List<CsLedgerVO> deviceList = allList.stream()
.filter(item -> item.getLevel().equals(LineBaseEnum.DEVICE_LEVEL.getCode()))
.collect(Collectors.toList());
lineTree = tree4.stream()
.filter(vo -> list1.contains(vo.getPid()))
.peek(item -> {
CsEquipmentDeliveryPO dev = devsMap.get(item.getId());
if (dev != null) {
item.setComFlag(dev.getRunStatus());
}
})
.collect(Collectors.toList());
List<CsLedgerVO> lineList = allList.stream()
.filter(item -> item.getLevel().equals(LineBaseEnum.LINE_LEVEL.getCode()))
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(deviceList)) {
CsLedgerVO government = new CsLedgerVO();
government.setLevel(0);
government.setName(DataParam.cldDev);
government.setPid("0");
government.setId(IdUtil.simpleUUID());
government.setChildren(engineeringList);
return government;
}
List<String> devIds = deviceList.stream().map(CsLedgerVO::getId).collect(Collectors.toList());
List<CsEquipmentDeliveryPO> devs = csEquipmentDeliveryMapper.selectBatchIds(devIds);
Map<String, CsEquipmentDeliveryPO> devsMap = devs.stream().collect(Collectors.toMap(CsEquipmentDeliveryPO::getId, Function.identity()));
Map<String, String> lineDevMap = lineList.stream().collect(Collectors.toMap(CsLedgerVO::getId, CsLedgerVO::getPid));
Set<String> cldDevIds = devs.stream()
.filter(item -> item.getDevType().equals(cldDevTypeId))
.map(CsEquipmentDeliveryPO::getId)
.collect(Collectors.toSet());
Map<String, List<CsLedgerVO>> projectToDeviceMap = deviceList.stream()
.collect(Collectors.groupingBy(CsLedgerVO::getPid));
Map<String, List<CsLedgerVO>> deviceToLineMap = lineList.stream()
.collect(Collectors.groupingBy(CsLedgerVO::getPid));
deviceList.forEach(device -> {
CsEquipmentDeliveryPO dev = devsMap.get(device.getId());
if (dev != null) {
device.setComFlag(dev.getRunStatus());
}
});
lineList.forEach(line -> {
String devId = lineDevMap.get(line.getId());
if (devId != null) {
CsEquipmentDeliveryPO dev = devsMap.get(devId);
if (dev != null) {
line.setComFlag(dev.getRunStatus());
}
}
}
});
if (CollectionUtil.isNotEmpty(deviceTree)) {
List<CsLedgerVO> finalLineTree = lineTree;
deviceTree.forEach(item -> {
item.setChildren(getChildren(item, finalLineTree));
});
}
if (CollectionUtil.isNotEmpty(projectTree)) {
List<CsLedgerVO> finalDeviceTree = deviceTree;
projectTree.forEach(item -> {
item.setChildren(getChildren(item, finalDeviceTree));
});
}
if (CollectionUtil.isNotEmpty(engineerTree)) {
List<CsLedgerVO> finalProjectTree = projectTree;
engineerTree.forEach(item -> {
item.setChildren(getChildren(item, finalProjectTree));
});
}
engineeringList.forEach(engineering -> {
List<CsLedgerVO> projectChildren = new ArrayList<>();
for (CsLedgerVO project : projectList) {
if (project.getPid().equals(engineering.getId())) {
List<CsLedgerVO> projectDevices = projectToDeviceMap.getOrDefault(project.getId(), new ArrayList<>());
if (CollectionUtil.isNotEmpty(projectDevices)) {
List<CsLedgerVO> deviceChildren = new ArrayList<>();
for (CsLedgerVO device : projectDevices) {
if (cldDevIds.contains(device.getId())) {
List<CsLedgerVO> lineChildren = deviceToLineMap.getOrDefault(device.getId(), new ArrayList<>());
device.setChildren(lineChildren);
deviceChildren.add(device);
}
}
project.setChildren(deviceChildren);
}
projectChildren.add(project);
}
}
engineering.setChildren(projectChildren);
});
CsLedgerVO government = new CsLedgerVO();
government.setLevel(0);
government.setName(DataParam.cldDev);
government.setPid("0");
government.setId(IdUtil.simpleUUID());
government.setChildren(engineerTree);
government.setChildren(engineeringList);
return government;
}
// @Override
// public CsLedgerVO cldTree() {
//
// List<CsLedgerVO> engineerTree = new ArrayList<>();
// List<CsLedgerVO> projectTree = new ArrayList<>();
// List<CsLedgerVO> deviceTree = new ArrayList<>();
// List<CsLedgerVO> lineTree = new ArrayList<>();
//
// List<CsLedgerVO> allList = this.baseMapper.getAll();
// if (CollectionUtil.isNotEmpty(allList)) {
// //工程集合
// List<CsLedgerVO> tree1 = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.ENGINEERING_LEVEL.getCode())).collect(Collectors.toList());
// //项目集合
// List<CsLedgerVO> tree2 = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.PROJECT_LEVEL.getCode())).collect(Collectors.toList());
// //设备集合
// List<CsLedgerVO> tree3 = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.DEVICE_LEVEL.getCode())).collect(Collectors.toList());
// //监测点集合
// List<CsLedgerVO> tree4 = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.LINE_LEVEL.getCode())).collect(Collectors.toList());
//
// //筛选出云前置设备
// if (CollectionUtil.isNotEmpty(tree3)) {
// Set<String> list1 = new HashSet<>();
// List<String> devList = tree3.stream().map(CsLedgerVO::getId).collect(Collectors.toList());
// List<CsEquipmentDeliveryPO> devs = csEquipmentDeliveryMapper.selectBatchIds(devList);
// Map<String, CsEquipmentDeliveryPO> devsMap = devs.stream().collect(Collectors.toMap(CsEquipmentDeliveryPO::getId, Function.identity()));
// DictTreeVO vo1 = dictTreeFeignClient.queryByCode(DicDataEnum.DEV_CLD.getCode()).getData();
//
// //list1是 cld设备
// devs.forEach(item -> {
// if (item.getDevType().equals(vo1.getId())) {
// list1.add(item.getId());
// }
// });
// //list2是 非cld设备
// Set<String> list2 = devList.stream().filter(item -> !list1.contains(item)).collect(Collectors.toSet());
// List<CsLedgerVO> tree5 = tree3.stream().filter(vo -> list2.contains(vo.getId())).collect(Collectors.toList());
// Set<String> list3 = tree5.stream().map(CsLedgerVO::getPid).collect(Collectors.toSet());
// projectTree = tree2.stream().filter(vo -> !list3.contains(vo.getId())).collect(Collectors.toList());
//
// List<CsLedgerVO> tree6 = tree2.stream().filter(vo -> list3.contains(vo.getId())).collect(Collectors.toList());
// Set<String> proList = tree6.stream().map(CsLedgerVO::getPid).collect(Collectors.toSet());
// engineerTree = tree1.stream().filter(vo -> !proList.contains(vo.getId())).collect(Collectors.toList());
//
// if (CollectionUtil.isNotEmpty(list1)) {
// deviceTree = tree3.stream()
// .filter(vo -> list1.contains(vo.getId()))
// .peek(item -> {
// CsEquipmentDeliveryPO dev = devsMap.get(item.getId());
// if (dev != null) {
// item.setComFlag(dev.getRunStatus());
// }
// })
// .collect(Collectors.toList());
//
// lineTree = tree4.stream()
// .filter(vo -> list1.contains(vo.getPid()))
// .peek(item -> {
// CsEquipmentDeliveryPO dev = devsMap.get(item.getId());
// if (dev != null) {
// item.setComFlag(dev.getRunStatus());
// }
// })
// .collect(Collectors.toList());
// }
// }
// }
//
// if (CollectionUtil.isNotEmpty(deviceTree)) {
// List<CsLedgerVO> finalLineTree = lineTree;
// deviceTree.forEach(item -> {
// item.setChildren(getChildren(item, finalLineTree));
// });
// }
// if (CollectionUtil.isNotEmpty(projectTree)) {
// List<CsLedgerVO> finalDeviceTree = deviceTree;
// projectTree.forEach(item -> {
// item.setChildren(getChildren(item, finalDeviceTree));
// });
// }
// if (CollectionUtil.isNotEmpty(engineerTree)) {
// List<CsLedgerVO> finalProjectTree = projectTree;
// engineerTree.forEach(item -> {
// item.setChildren(getChildren(item, finalProjectTree));
// });
// }
//
// CsLedgerVO government = new CsLedgerVO();
// government.setLevel(0);
// government.setName(DataParam.cldDev);
// government.setPid("0");
// government.setId(IdUtil.simpleUUID());
// government.setChildren(engineerTree);
//
// return government;
// }
@Override
public List<DevDetailDTO> getInfoByIds(List<String> list) {
List<DevDetailDTO> details = new ArrayList<>();
@@ -1100,20 +1382,47 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
@Override
public List<DevDetailDTO> getDevInfoByEngineerIds(List<String> list) {
List<DevDetailDTO> details = new ArrayList<>();
//工程
LambdaQueryWrapper<CsLedger> queryWrapper0 = new LambdaQueryWrapper<>();
queryWrapper0.in(CsLedger::getId, list);
List<CsLedger> engineering = this.list(queryWrapper0);
Map<String, CsLedger> engineeringMap = engineering.stream().collect(Collectors.toMap(CsLedger::getId, item -> item));
//项目
LambdaQueryWrapper<CsLedger> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(CsLedger::getPid, list);
List<CsLedger> project = this.list(queryWrapper);
//工程id
Map<String, CsLedger> projectMap = project.stream().collect(Collectors.toMap(CsLedger::getId, item -> item));
//设备
List<String> projectIds = project.stream().map(CsLedger::getId).collect(Collectors.toList());
LambdaQueryWrapper<CsLedger> queryWrapper2 = new LambdaQueryWrapper<>();
queryWrapper2.in(CsLedger::getPid, projectIds);
List<CsLedger> dev = this.list(queryWrapper2);
dev.forEach(item -> {
DevDetailDTO detail = new DevDetailDTO();
detail.setEquipmentName(item.getName());
detail.setEquipmentId(item.getId());
details.add(detail);
});
if (CollectionUtil.isNotEmpty(dev)) {
List<String> devIds = dev.stream().map(CsLedger::getId).collect(Collectors.toList());
List<CsEquipmentDeliveryPO> devs = csEquipmentDeliveryMapper.selectBatchIds(devIds);
Map<String, CsEquipmentDeliveryPO> devsMap = devs.stream().collect(Collectors.toMap(CsEquipmentDeliveryPO::getId, item -> item));
dev.forEach(item -> {
DevDetailDTO detail = new DevDetailDTO();
detail.setEquipmentName(item.getName());
detail.setEquipmentId(item.getId());
CsLedger csLedger = projectMap.get(item.getPid());
detail.setProjectId(csLedger.getId());
detail.setProjectName(csLedger.getName());
CsLedger csLedger1 = engineeringMap.get(csLedger.getPid());
detail.setEngineeringid(csLedger1.getId());
detail.setEngineeringName(csLedger1.getName());
detail.setRunStatus(devsMap.get(item.getId()).getRunStatus());
details.add(detail);
});
}
return details;
}

View File

@@ -16,6 +16,7 @@ import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.csdevice.enums.LineBaseEnum;
import com.njcn.csdevice.mapper.*;
import com.njcn.csdevice.pojo.dto.CsLineDTO;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.*;
import com.njcn.csdevice.pojo.vo.LineDetailDataVO;
@@ -24,7 +25,7 @@ import com.njcn.csdevice.service.CsDevModelService;
import com.njcn.csdevice.service.CsLinePOService;
import com.njcn.csdevice.service.ICsDataSetService;
import com.njcn.csharmonic.api.PqSensitiveUserFeignClient;
import com.njcn.csharmonic.pojo.po.PqSensitiveUser;
import com.njcn.device.biz.pojo.po.PqSensitiveUser;
import com.njcn.oss.constant.OssPath;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.system.api.DicDataFeignClient;
@@ -153,8 +154,8 @@ public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> i
List<CsDataSet> list = csDataSetService.findDataSetByModelId(po1.getId());
if (CollectionUtil.isNotEmpty(list)) {
po.setDataSetId(list.get(0).getId());
po.setClDid(list.get(0).getClDev());
}
po.setClDid(param.getLineNo());
//监测位置
//DictData data = dicDataFeignClient.getDicDataByCode(DicDataEnum.GRID_SIDE.getCode()).getData();
po.setPosition(param.getPosition());
@@ -270,6 +271,11 @@ public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> i
.collect(Collectors.toList());
}
@Override
public List<CsLineDTO> getAllLineDetail() {
return this.baseMapper.findLineList();
}
@Override
public List<CsLinePO> getSimpleLine() {
List<String> devIds = commGetDevIds(RequestUtil.getUserIndex());

View File

@@ -0,0 +1,184 @@
package com.njcn.csdevice.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.csdevice.mapper.CsUserPinsMapper;
import com.njcn.csdevice.param.CsUserPinsParam;
import com.njcn.csdevice.pojo.po.CsUserPins;
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import com.njcn.csdevice.service.ICsUserPinsService;
import com.njcn.web.utils.RequestUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* <p>
* 用户置顶表 服务实现类
* </p>
*
* @author xy
* @since 2026-03-04
*/
@Service
public class CsUserPinsServiceImpl extends ServiceImpl<CsUserPinsMapper, CsUserPins> implements ICsUserPinsService {
@Override
public boolean engineeringPinToTop(CsUserPinsParam param) {
LambdaUpdateWrapper<CsUserPins> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(CsUserPins::getUserId, param.getUserId())
.eq(CsUserPins::getTargetId, param.getTargetId())
.eq(CsUserPins::getTargetType, param.getTargetType());
CsUserPins csUserPins = this.getOne(wrapper);
//为空,则是置顶
if (Objects.isNull(csUserPins)) {
CsUserPins po = new CsUserPins();
BeanUtils.copyProperties(param, po);
this.save(po);
}
//有数据则是取消置顶
else {
this.removeById(csUserPins.getId());
}
return true;
}
@Override
public List<CsUserPins> getPinToTopList() {
LambdaUpdateWrapper<CsUserPins> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(CsUserPins::getUserId, RequestUtil.getUserIndex())
.orderByDesc(CsUserPins::getCreateTime);
return this.list(wrapper);
}
@Override
public void channelTree(List<CsUserPins> list, List<CsLedgerVO> tree, Integer level) {
List<String> targetIdList = new ArrayList<>();
List<String> devList = new ArrayList<>();
switch (level) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
// 处理工程置顶(第一层)
targetIdList = list.stream()
.filter(item -> Objects.equals(item.getTargetType(), 2))
.map(CsUserPins::getTargetId)
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(targetIdList)) {
sortByTargetList(tree, targetIdList);
}
// 处理设备置顶(第三层)
devList = list.stream()
.filter(item -> Objects.equals(item.getTargetType(), 1))
.map(CsUserPins::getTargetId)
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(devList)) {
// 遍历 tree找到第三层的数据进行排序
for (CsLedgerVO firstLevelNode : tree) {
if (firstLevelNode.getLevel() == 0 && CollectionUtil.isNotEmpty(firstLevelNode.getChildren())) {
// 第二层
for (CsLedgerVO secondLevelNode : firstLevelNode.getChildren()) {
if (CollectionUtil.isNotEmpty(secondLevelNode.getChildren())) {
// 第三层
sortByTargetList(secondLevelNode.getChildren(), devList);
}
}
}
}
}
break;
case 5:
// 处理工程置顶(第二层,因为最上面加了一层)
targetIdList = list.stream()
.filter(item -> Objects.equals(item.getTargetType(), 2))
.map(CsUserPins::getTargetId)
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(targetIdList)) {
sortSecondLevelByTargetList(tree, targetIdList);
}
// 处理设备置顶(第四层)
devList = list.stream()
.filter(item -> Objects.equals(item.getTargetType(), 1))
.map(CsUserPins::getTargetId)
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(devList)) {
sortFourthLevelByDevList(tree, devList);
}
break;
default:
break;
}
}
/**
* 根据目标 ID 列表对节点列表进行排序
* @param nodeList 需要排序的节点列表
* @param targetIdList 目标 ID 列表(决定排序顺序)
*/
private void sortByTargetList(List<CsLedgerVO> nodeList, List<String> targetIdList) {
// 分离出匹配 targetIdList 的节点和未匹配的节点
List<CsLedgerVO> matchedList = new ArrayList<>();
List<CsLedgerVO> unmatchedList = new ArrayList<>();
for (CsLedgerVO node : nodeList) {
if (targetIdList.contains(node.getId())) {
node.setIsTop(1);
matchedList.add(node);
} else {
unmatchedList.add(node);
}
}
// 根据 targetIdList 的顺序对匹配的节点进行排序
matchedList.sort(Comparator.comparingInt(node -> targetIdList.indexOf(node.getId())));
// 未匹配的节点按照原有的 sort 字段排序,处理 null 值情况
unmatchedList.sort(Comparator.comparing(node -> node.getSort() != null ? node.getSort() : Integer.MAX_VALUE));
// 清空原列表并添加排序后的数据
nodeList.clear();
nodeList.addAll(matchedList);
nodeList.addAll(unmatchedList);
}
/**
* 根据目标 ID 列表对第二层节点进行排序(因为最上面加了一层)
*/
private void sortSecondLevelByTargetList(List<CsLedgerVO> tree, List<String> targetIdList) {
for (CsLedgerVO firstLevelNode : tree) {
if (CollectionUtil.isNotEmpty(firstLevelNode.getChildren())) {
sortByTargetList(firstLevelNode.getChildren(), targetIdList);
}
}
}
/**
* 根据设备 ID 列表对第四层节点进行排序
*/
private void sortFourthLevelByDevList(List<CsLedgerVO> tree, List<String> devList) {
for (CsLedgerVO firstLevelNode : tree) {
if (CollectionUtil.isNotEmpty(firstLevelNode.getChildren())) {
for (CsLedgerVO secondLevelNode : firstLevelNode.getChildren()) {
if (CollectionUtil.isNotEmpty(secondLevelNode.getChildren())) {
for (CsLedgerVO thirdLevelNode : secondLevelNode.getChildren()) {
if (CollectionUtil.isNotEmpty(thirdLevelNode.getChildren())) {
// 第四层
sortByTargetList(thirdLevelNode.getChildren(), devList);
}
}
}
}
}
}
}
}

View File

@@ -31,8 +31,10 @@ import com.njcn.mq.message.BZEventMessage;
import com.njcn.mq.template.BZEventMessageTemplate;
import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.DictTreeFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.SysDicTreePO;
import com.njcn.system.pojo.vo.DictTreeVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
@@ -63,6 +65,7 @@ class IcdServiceImpl implements IcdService {
private final ICsTerminalLogsService csTerminalLogsService;
private final ICsTerminalReplyService csTerminalReplyService;
private final OverLimitWlMapper overLimitWlMapper;
private final DictTreeFeignClient dictTreeFeignClient;
private final DateTimeFormatter microsecondFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
@Override
@@ -537,7 +540,13 @@ class IcdServiceImpl implements IcdService {
// 设置设备信息
List<CsEquipmentDeliveryPO> devList = csEquipmentDeliveryService.getDevListByProjectId(id);
if (CollectionUtil.isNotEmpty(devList)) {
vo.setDeviceInfoList(devList);
//如果不是监测设备,则不展示
DictTreeVO cldDict = dictTreeFeignClient.queryByCode(DicDataEnum.DEV_CLD.getCode()).getData();
String cldDevTypeId = cldDict.getId();
List<CsEquipmentDeliveryPO> cldDevIds = devList.stream()
.filter(item -> item.getDevType().equals(cldDevTypeId))
.collect(Collectors.toList());
vo.setDeviceInfoList(cldDevIds);
}
}