From b078f17db801d54e2d90c76a082dc34a82c8a269 Mon Sep 17 00:00:00 2001 From: wangrunpu <2095588299@qq.com> Date: Tue, 3 Feb 2026 16:01:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=89=A9=E8=81=94=E7=BD=91=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=BC=82=E6=AD=A5=E5=A4=84=E7=90=86=EF=BC=9B=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=A0=B9=E6=8D=AE=E7=A7=9F=E6=88=B7id=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=BC=81=E4=B8=9A=E4=BF=A1=E6=81=AF=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/local/IotLocalMessageBus.java | 2 + .../tcp/manager/IotTcpConnectionManager.java | 2 +- .../DustCompanyinfoController.java | 15 +++++ .../DustCompanyinfoService.java | 2 + .../DustCompanyinfoServiceImpl.java | 56 ++++++++++++++++--- .../DustEquipinfoServiceImpl.java | 24 ++++---- 6 files changed, 80 insertions(+), 21 deletions(-) diff --git a/yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/messagebus/core/local/IotLocalMessageBus.java b/yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/messagebus/core/local/IotLocalMessageBus.java index 1fc608bc5..a2e06ca7b 100644 --- a/yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/messagebus/core/local/IotLocalMessageBus.java +++ b/yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/messagebus/core/local/IotLocalMessageBus.java @@ -7,6 +7,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.ApplicationContext; import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; import java.util.ArrayList; import java.util.HashMap; @@ -46,6 +47,7 @@ public class IotLocalMessageBus implements IotMessageBus { topic, subscriber.getGroup(), subscriber.getClass().getName()); } + @Async @EventListener @SuppressWarnings({"unchecked", "rawtypes"}) public void onMessage(IotLocalMessage message) { diff --git a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/manager/IotTcpConnectionManager.java b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/manager/IotTcpConnectionManager.java index c0d209814..371883e53 100644 --- a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/manager/IotTcpConnectionManager.java +++ b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/manager/IotTcpConnectionManager.java @@ -39,7 +39,7 @@ public class IotTcpConnectionManager { * @param deviceId 设备 ID * @param connectionInfo 连接信息 */ - public void registerConnection(NetSocket socket, Long deviceId, ConnectionInfo connectionInfo) { + public synchronized void registerConnection(NetSocket socket, Long deviceId, ConnectionInfo connectionInfo) { // 如果设备已有其他连接,先清理旧连接 NetSocket oldSocket = deviceSocketMap.get(deviceId); if (oldSocket != null && oldSocket != socket) { diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dustcompanyinfo/DustCompanyinfoController.java b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dustcompanyinfo/DustCompanyinfoController.java index 6edd32da2..c2152200d 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dustcompanyinfo/DustCompanyinfoController.java +++ b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dustcompanyinfo/DustCompanyinfoController.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.system.controller.admin.dustcompanyinfo; +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.module.system.controller.admin.dustdustinfo.vo.DustDustinfoRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.dustdustinfo.DustDustinfoDO; import cn.iocoder.yudao.module.system.dal.dataobject.dusttype.DustTypeDO; @@ -29,6 +31,7 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser; import cn.iocoder.yudao.module.system.controller.admin.dustcompanyinfo.vo.*; import cn.iocoder.yudao.module.system.dal.dataobject.dustcompanyinfo.DustCompanyinfoDO; @@ -111,6 +114,18 @@ public class DustCompanyinfoController { return success(respVO); } + @GetMapping("/get-by-tenant") + @Operation(summary = "通过租户id获得企业基础信息") + @Parameter(name = "tenantId", description = "租户编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('system:dust-companyinfo:query')") + public CommonResult getDustCompanyinfoByTenantId(@RequestParam("tenantId") Long tenantId) { + if (ObjectUtil.isNull(tenantId)) { + LoginUser loginUser = getLoginUser(); + tenantId = loginUser.getTenantId(); + } + return success(dustCompanyinfoService.getCompanyinfoByTenantId(tenantId)); + } + @GetMapping("/page") @Operation(summary = "获得企业基础信息分页") @PreAuthorize("@ss.hasPermission('system:dust-companyinfo:query')") diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustcompanyinfo/DustCompanyinfoService.java b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustcompanyinfo/DustCompanyinfoService.java index 65e3b3dc6..053372af0 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustcompanyinfo/DustCompanyinfoService.java +++ b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustcompanyinfo/DustCompanyinfoService.java @@ -60,4 +60,6 @@ public interface DustCompanyinfoService { PageResult getDustCompanyinfoPage(DustCompanyinfoPageReqVO pageReqVO); String getDataIdByTenantId(Long tenantId); + + DustCompanyinfoRespVO getCompanyinfoByTenantId(Long tenantId); } diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustcompanyinfo/DustCompanyinfoServiceImpl.java b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustcompanyinfo/DustCompanyinfoServiceImpl.java index 231386094..052768c75 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustcompanyinfo/DustCompanyinfoServiceImpl.java +++ b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustcompanyinfo/DustCompanyinfoServiceImpl.java @@ -1,25 +1,30 @@ package cn.iocoder.yudao.module.system.service.dustcompanyinfo; -import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; +import cn.iocoder.yudao.module.system.controller.admin.dustdustinfo.vo.DustDustinfoRespVO; import cn.iocoder.yudao.module.system.controller.admin.dustdustinfo.vo.DustDustinfoSaveReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.dustdustinfo.DustDustinfoDO; +import cn.iocoder.yudao.module.system.dal.dataobject.dusttype.DustTypeDO; import cn.iocoder.yudao.module.system.service.dustdustinfo.DustDustinfoService; +import cn.iocoder.yudao.module.system.service.dusttype.DustTypeService; import org.springframework.stereotype.Service; import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; + import cn.iocoder.yudao.module.system.controller.admin.dustcompanyinfo.vo.*; import cn.iocoder.yudao.module.system.dal.dataobject.dustcompanyinfo.DustCompanyinfoDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.dal.mysql.dustcompanyinfo.DustCompanyinfoMapper; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; /** @@ -36,6 +41,8 @@ public class DustCompanyinfoServiceImpl implements DustCompanyinfoService { @Resource private DustDustinfoService dustDustinfoService; + @Resource + private DustTypeService dustTypeService; @Override @Transactional(rollbackFor = Exception.class) public String createDustCompanyinfo(DustCompanyinfoSaveReqVO createReqVO) { @@ -104,11 +111,44 @@ public class DustCompanyinfoServiceImpl implements DustCompanyinfoService { @Override public String getDataIdByTenantId(Long tenantId) { - DustCompanyinfoDO selectedOne = dustCompanyinfoMapper.selectOne("tenantId", tenantId); - if (selectedOne == null || selectedOne.getDeleted()) { - return null; - } - return selectedOne.getDataId(); + AtomicReference selectedOne = new AtomicReference<>(); + return TenantUtils.executeIgnore(() -> { + selectedOne.set(dustCompanyinfoMapper.selectOne("tenant_id", tenantId)); + if (selectedOne.get() == null || selectedOne.get().getDeleted()) { + return null; + } + + return selectedOne.get().getDataId(); + }); + } + + @Override + public DustCompanyinfoRespVO getCompanyinfoByTenantId(Long tenantId){ + return TenantUtils.executeIgnore(() -> { + //查询企业基础信息 + DustCompanyinfoDO dustCompanyinfo = dustCompanyinfoMapper.selectOne("tenant_id",tenantId); + if (ObjectUtil.isNull(dustCompanyinfo)) return null; + DustCompanyinfoRespVO respVO = BeanUtils.toBean(dustCompanyinfo, DustCompanyinfoRespVO.class); + //根据id查询企业涉尘信息 + DustDustinfoDO dustDustinfo = dustDustinfoService.getDustDustinfo(dustCompanyinfo.getId()); + List list = Arrays.stream(dustDustinfo.getDustTechnology().split(",")).toList(); + DustDustinfoRespVO dustinfoRespVO = BeanUtils.toBean(dustDustinfo, DustDustinfoRespVO.class); + dustinfoRespVO.setDustTechnology(list); + String fullDustName=""; + if (dustDustinfo.getDustType() != null ){ + DustTypeDO dustType = dustTypeService.getDustType(dustDustinfo.getDustType()); + if (dustType != null && dustType.getName()!=null){ + fullDustName = dustType.getName(); + DustTypeDO dustType1 = dustTypeService.getDustType(dustType.getParentId()); + if (dustType1!=null && dustType1.getName()!=null){ + fullDustName = dustType1.getName()+"/"+fullDustName; + } + } + dustinfoRespVO.setDustTypeName(fullDustName); + } + respVO.setDustDustinfo(dustinfoRespVO); + return respVO; + }); } } diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustequipinfo/DustEquipinfoServiceImpl.java b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustequipinfo/DustEquipinfoServiceImpl.java index d88501c03..8a1b45029 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustequipinfo/DustEquipinfoServiceImpl.java +++ b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/service/dustequipinfo/DustEquipinfoServiceImpl.java @@ -51,18 +51,18 @@ public class DustEquipinfoServiceImpl implements DustEquipinfoService { // createReqVO.setEquipCode(String.valueOf(maxEquipCode + 1l)); // } // 使用 Optional 链式操作进行改造(体验一下函数式编程) - Optional.ofNullable(getLoginUser()) - .map(LoginUser::getTenantId) - .map(tenantId -> dustCompanyinfoService.getDataIdByTenantId(tenantId)) - .ifPresent(dataId -> { - createReqVO.setDataId(dataId); - // 继续查询最大设备编码 - Long maxCode = Optional.ofNullable(dustEquipinfoMapper.getMaxEquipCode(dataId)) - .filter(code -> code > 0) - .map(code -> code + 1) - .orElse(Long.valueOf(dataId+"001")); // 默认从1开始 - createReqVO.setEquipCode(String.valueOf(maxCode)); - }); +// Optional.ofNullable(getLoginUser()) +// .map(LoginUser::getTenantId) +// .map(tenantId -> dustCompanyinfoService.getDataIdByTenantId(tenantId)) +// .ifPresent(dataId -> { +// createReqVO.setDataId(dataId); +// // 继续查询最大设备编码 +// Long maxCode = Optional.ofNullable(dustEquipinfoMapper.getMaxEquipCode(dataId)) +// .filter(code -> code > 0) +// .map(code -> code + 1) +// .orElse(Long.valueOf(dataId+"001")); // 默认从1开始 +// createReqVO.setEquipCode(String.valueOf(maxCode)); +// }); DustEquipinfoDO dustEquipinfo = BeanUtils.toBean(createReqVO, DustEquipinfoDO.class); dustEquipinfo.setDustTechnology(join); dustEquipinfoMapper.insert(dustEquipinfo);