优化暂态事件推送时部门数据的获取

This commit is contained in:
xy
2025-07-30 11:23:21 +08:00
parent 6c2ddfab67
commit c9ecdad7ed
6 changed files with 45 additions and 14 deletions

View File

@@ -1,9 +1,12 @@
package com.njcn.device.pq.api; package com.njcn.device.pq.api;
import com.njcn.common.pojo.constant.ServerInfo; import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pq.api.fallback.DeptLineFeignClientFallbackFactory; import com.njcn.device.pq.api.fallback.DeptLineFeignClientFallbackFactory;
import com.njcn.device.pq.pojo.po.DeptLine; import com.njcn.device.pq.pojo.po.DeptLine;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@@ -40,6 +43,10 @@ public interface DeptLineFeignClient {
@PostMapping("/getLineByLineIds") @PostMapping("/getLineByLineIds")
HttpResult<DeptLine> getLineByLineIds(@RequestParam("id") String ids); HttpResult<DeptLine> getLineByLineIds(@RequestParam("id") String ids);
@PostMapping("/getDeptListByLineId")
HttpResult<List<DeptLine>> getDeptListByLineId(@RequestParam("id") String ids);
/** /**
* @Description: 部门Id获取所有子集部门绑定监测点 * @Description: 部门Id获取所有子集部门绑定监测点
* @Param: * @Param:

View File

@@ -7,6 +7,7 @@ import com.njcn.device.pq.api.DeptLineFeignClient;
import com.njcn.device.biz.utils.DeviceEnumUtil; import com.njcn.device.biz.utils.DeviceEnumUtil;
import com.njcn.device.pq.pojo.po.DeptLine; import com.njcn.device.pq.pojo.po.DeptLine;
import feign.hystrix.FallbackFactory; import feign.hystrix.FallbackFactory;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -69,6 +70,12 @@ public class DeptLineFeignClientFallbackFactory implements FallbackFactory<DeptL
throw new BusinessException(finalExceptionEnum); throw new BusinessException(finalExceptionEnum);
} }
@Override
public HttpResult<List<DeptLine>> getDeptListByLineId(String ids) {
log.error("{}异常,降级处理,异常为:{}", "根据监测点获取部门id(集合)", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override @Override
public HttpResult<List<String>> getLineNodeByDeptId(String id) { public HttpResult<List<String>> getLineNodeByDeptId(String id) {
log.error("{}异常,降级处理,异常为:{}", "根据部门信息id查询监测点id集合", throwable.toString()); log.error("{}异常,降级处理,异常为:{}", "根据部门信息id查询监测点id集合", throwable.toString());

View File

@@ -148,6 +148,14 @@ public class DeptLineController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineByLineIds, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineByLineIds, methodDescribe);
} }
@PostMapping("/getDeptListByLineId")
@ApiOperation("根据监测点获取部门id(集合)")
public HttpResult<List<DeptLine>> getDeptListByLineId(@RequestParam("id") String ids) {
String methodDescribe = getMethodDescribe("getDeptListByLineId");
List<DeptLine> lineByLineIds = deptLineService.getDeptListByLineId(ids);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineByLineIds, methodDescribe);
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON) @OperateInfo(info = LogEnum.SYSTEM_COMMON)
@PostMapping("/getLineNodeByDeptId") @PostMapping("/getLineNodeByDeptId")
@ApiOperation("部门Id获取所有子集部门绑定监测点") @ApiOperation("部门Id获取所有子集部门绑定监测点")

View File

@@ -128,6 +128,8 @@ public interface DeptLineService extends IService<DeptLine> {
*/ */
DeptLine getLineByLineIds(String ids); DeptLine getLineByLineIds(String ids);
List<DeptLine> getDeptListByLineId(String id);
List<LineDeviceStateVO> getLineDetailByDeptId(String id); List<LineDeviceStateVO> getLineDetailByDeptId(String id);

View File

@@ -35,10 +35,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -194,6 +192,12 @@ public class DeptLineServiceImpl extends ServiceImpl<DeptLineMapper, DeptLine> i
); );
} }
@Override
public List<DeptLine> getDeptListByLineId(String id) {
return this.list(new LambdaQueryWrapper<DeptLine>()
.eq(DeptLine::getLineId, id));
}
@Override @Override
public List<LineDeviceStateVO> getLineDetailByDeptId(String id) { public List<LineDeviceStateVO> getLineDetailByDeptId(String id) {
List<String> lineByDeptId = this.getLineNodeByDeptId(id); List<String> lineByDeptId = this.getLineNodeByDeptId(id);

View File

@@ -1,6 +1,7 @@
package com.njcn.event.service.majornetwork.Impl; package com.njcn.event.service.majornetwork.Impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@@ -186,19 +187,21 @@ public class EventDetailServiceImpl extends ServiceImpl<EventDetailMapper, RmpEv
private void pushEvent(RmpEventDetailPO po) { private void pushEvent(RmpEventDetailPO po) {
String id = po.getLineId(); String id = po.getLineId();
//根据监测点获取部门 //根据监测点获取部门
DeptLine deptLine = deptLineFeignClient.getLineByLineIds(id).getData(); List<DeptLine> deptLineList = deptLineFeignClient.getDeptListByLineId(id).getData();
if(Objects.nonNull(deptLine)){ if (CollUtil.isNotEmpty(deptLineList)) {
String deptLineId = deptLine.getId();
Set<String> dept = new HashSet<>(); Set<String> dept = new HashSet<>();
deptLineList.forEach(item->{
String deptLineId = item.getId();
dept.add(deptLineId); dept.add(deptLineId);
DeptGetLineParam deptGetLineParam = new DeptGetLineParam(); DeptGetLineParam deptGetLineParam = new DeptGetLineParam();
deptGetLineParam.setDeptId(deptLineId); deptGetLineParam.setDeptId(deptLineId);
List<DeptGetBase> deptList = commTerminalGeneralClient.getDeptChildrenByParent(deptGetLineParam).getData(); List<DeptGetBase> deptList = commTerminalGeneralClient.getDeptChildrenByParent(deptGetLineParam).getData();
if (CollectionUtil.isNotEmpty(deptList)) { if (CollectionUtil.isNotEmpty(deptList)) {
deptList.forEach(item->{ deptList.forEach(item2->{
dept.addAll(item.getUnitChildrenList()); dept.addAll(item2.getUnitChildrenList());
}); });
} }
});
SendEventVO vo = new SendEventVO(); SendEventVO vo = new SendEventVO();
vo.setDeptList(dept); vo.setDeptList(dept);
vo.setTime(po.getStartTime()); vo.setTime(po.getStartTime());