From bbd895f1161034fb172f2fda92dbfcd711785f86 Mon Sep 17 00:00:00 2001 From: zcxlsm Date: Tue, 5 Aug 2025 10:51:31 +0800 Subject: [PATCH] refactor(sis): 1 --- .../sis/domain/SisElevatorFloorRef.java | 10 ++ .../dromara/sis/sdk/huawei/HuaWeiBoxApi.java | 5 +- .../huawei/service/HuaWeiBoxApiService.java | 31 +++++- .../service/ISisElevatorFloorRefService.java | 8 ++ ...SisElevatorFloorChannelRefServiceImpl.java | 1 + .../impl/SisElevatorFloorRefServiceImpl.java | 21 ++++ .../impl/SisElevatorInfoServiceImpl.java | 100 +++++++----------- 7 files changed, 110 insertions(+), 66 deletions(-) diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/SisElevatorFloorRef.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/SisElevatorFloorRef.java index 6df2a47a..3d5d4266 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/SisElevatorFloorRef.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/domain/SisElevatorFloorRef.java @@ -42,5 +42,15 @@ public class SisElevatorFloorRef extends TenantEntity { */ private Long authGroupId; + /** + * 内部通道号 + */ + private Long inChannel; + + /** + * 外部通道号 + */ + private Long outChannel; + } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/huawei/HuaWeiBoxApi.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/huawei/HuaWeiBoxApi.java index 397c5e7d..b20da6c0 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/huawei/HuaWeiBoxApi.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/huawei/HuaWeiBoxApi.java @@ -4,6 +4,7 @@ import org.dromara.sis.sdk.huawei.domain.AddHWPersonReq; import java.util.Collection; import java.util.List; +import java.util.Map; /** * @apiNote HuaWeiBoxApi @@ -32,7 +33,7 @@ public interface HuaWeiBoxApi { * 根据抓拍图片比对,返回人员ID * * @param base64Img 入参 - * @return Long + * @return Map */ - Long findPerson(String base64Img); + Map findPerson(String base64Img); } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/huawei/service/HuaWeiBoxApiService.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/huawei/service/HuaWeiBoxApiService.java index b89ce154..06aef232 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/huawei/service/HuaWeiBoxApiService.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/sdk/huawei/service/HuaWeiBoxApiService.java @@ -12,7 +12,9 @@ import org.dromara.sis.sdk.huawei.utils.HuaWeiHttp; import org.springframework.stereotype.Service; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -86,7 +88,7 @@ public class HuaWeiBoxApiService implements HuaWeiBoxApi { * @return Long */ @Override - public Long findPerson(String base64Img) { + public Map findPerson(String base64Img) { String url = "/sdk_service/rest/facerepositories/peoples"; FinaHWPersonReq req = new FinaHWPersonReq(); @@ -97,23 +99,42 @@ public class HuaWeiBoxApiService implements HuaWeiBoxApi { String jsonReq = JSONUtil.toJsonStr(req); String jsonStrRes = huaWeiHttp.doPost(url, jsonReq); JSONObject jsonRes = JSONUtil.parseObj(jsonStrRes); + Map result = new HashMap<>(); if (jsonRes.getInt("resultCode") != 0) { - log.error("调用华为盒子人脸比对接口失败,code:{},msg:{}", jsonRes.getInt("resultCode"), jsonRes.getStr("resultMsg")); - return null; + switch (jsonRes.getInt("resultCode")) { + case 912322041: + result.put("code", 912322041); + result.put("msg", "特征值提取失败"); + break; + case 912322022: + result.put("code", 912333003); + result.put("msg", "base64参数非法"); + break; + default: + result.put("code", jsonRes.getInt("resultCode")); + result.put("msg", jsonRes.getStr("resultMsg")); + break; + } + log.info("调用华为盒子人脸比对接口失败,code:{},msg:{}", jsonRes.getInt("resultCode"), jsonRes.getStr("resultMsg")); + return result; } JSONArray jsonArr = jsonRes.getJSONArray("algorithmResults"); JSONObject obj = jsonArr.getJSONObject(0); if (Integer.parseInt(obj.getStr("number")) == 0) { - log.error("无人脸比对数据"); + result.put("code", 201); + result.put("msg", "无匹配数据"); + log.info("无人脸比对数据"); return null; } JSONArray peopleList = obj.getJSONArray("peopleList"); JSONObject people = peopleList.getJSONObject(0); - return Long.parseLong(people.getStr("peopleId")); + result.put("code", 200); + result.put("msg", Long.parseLong(people.getStr("peopleId"))); + return result; } } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisElevatorFloorRefService.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisElevatorFloorRefService.java index d8e39b17..69b4ff9d 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisElevatorFloorRefService.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisElevatorFloorRefService.java @@ -1,5 +1,6 @@ package org.dromara.sis.service; +import org.dromara.sis.domain.SisElevatorFloorChannelRef; import org.dromara.sis.domain.vo.SisElevatorFloorRefVo; import org.dromara.sis.domain.bo.SisElevatorFloorRefBo; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -72,4 +73,11 @@ public interface ISisElevatorFloorRefService { * @param authGroupId 电梯id */ List queryByAuthGroupId(Long authGroupId); + + /** + * 批量更新电梯⇄楼层通道关联信息 + * + * @param info 通道信息 + */ + Boolean batchUpdateChannel(Collection info); } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorFloorChannelRefServiceImpl.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorFloorChannelRefServiceImpl.java index 74c036eb..f8b96df8 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorFloorChannelRefServiceImpl.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorFloorChannelRefServiceImpl.java @@ -150,6 +150,7 @@ public class SisElevatorFloorChannelRefServiceImpl implements ISisElevatorFloorC lqw.eq(SisElevatorFloorChannelRef::getElevatorId, elevatorId); baseMapper.delete(lqw); + // 写入通道关系 boolean flag = baseMapper.insertBatch(bo); Assert.isTrue(flag, "批量增加电梯⇄楼层⇄通道关联信息失败"); return flag; diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorFloorRefServiceImpl.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorFloorRefServiceImpl.java index c7bd4bab..43e932e0 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorFloorRefServiceImpl.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorFloorRefServiceImpl.java @@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.dromara.sis.domain.SisElevatorFloorChannelRef; import org.springframework.stereotype.Service; import org.dromara.sis.domain.bo.SisElevatorFloorRefBo; import org.dromara.sis.domain.vo.SisElevatorFloorRefVo; @@ -151,4 +152,24 @@ public class SisElevatorFloorRefServiceImpl implements ISisElevatorFloorRefServi lqw.eq(SisElevatorFloorRef::getElevatorId, authGroupId); return baseMapper.selectVoList(lqw); } + + /** + * 批量更新电梯⇄楼层通道关联信息 + * + * @param info 通道信息 + */ + @Override + public Boolean batchUpdateChannel(Collection info){ + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.in(SisElevatorFloorRef::getFloorId, info.stream().map(SisElevatorFloorChannelRef::getFloorId).toList()); + List list = baseMapper.selectList(lqw); + + + for (SisElevatorFloorRef item : list){ + item.setInChannel(info.stream().filter(x -> x.getFloorId().equals(item.getFloorId())).findFirst().get().getInChannel()); + } + + return false; + + } } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorInfoServiceImpl.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorInfoServiceImpl.java index bb48eae2..08819ef0 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorInfoServiceImpl.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisElevatorInfoServiceImpl.java @@ -24,6 +24,7 @@ import org.dromara.sis.domain.vo.SisElevatorInfoVo; import org.dromara.sis.mapper.SisElevatorInfoMapper; import org.dromara.sis.service.ISisDeviceBindRefService; import org.dromara.sis.service.ISisElevatorFloorChannelRefService; +import org.dromara.sis.service.ISisElevatorFloorRefService; import org.dromara.sis.service.ISisElevatorInfoService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -45,6 +46,7 @@ public class SisElevatorInfoServiceImpl implements ISisElevatorInfoService { private final SisElevatorInfoMapper baseMapper; private final ISisDeviceBindRefService deviceBindRefService; + private final ISisElevatorFloorRefService elevatorFloorRefService; private final ISisElevatorFloorChannelRefService elevatorFloorChannelRefService; @DubboReference @@ -71,7 +73,7 @@ public class SisElevatorInfoServiceImpl implements ISisElevatorInfoService { deviceInfo.setDeviceIp(item.getDeviceIp()); if (Objects.equals(item.getControlType(), ControlTypeEnum.REMOTE_CALL_ELEVATOR.getCode())) { remoteCallElevatorDeviceId.add(deviceInfo); - }else { + } else { sisElevatorInfoVo.setElevatorControlDeviceId(deviceInfo); } sisElevatorInfoVo.setRemoteCallElevatorDeviceId(remoteCallElevatorDeviceId); @@ -159,53 +161,13 @@ public class SisElevatorInfoServiceImpl implements ISisElevatorInfoService { if (flag) { bo.setElevatorId(add.getElevatorId()); - List ls = new ArrayList<>(); - // 梯控 - if (bo.getElevatorControlDeviceId() != null) { - SisDeviceBindRef ref = new SisDeviceBindRef(); - ref.setDeviceId(bo.getElevatorControlDeviceId().getDeviceId()); - ref.setDeviceIp(bo.getElevatorControlDeviceId().getDeviceIp()); - ref.setBindId(bo.getElevatorId()); - ref.setControlType(ControlTypeEnum.ELEVATOR_CONTROL.getCode()); - ls.add(ref); - } - // 远程呼叫 - if (bo.getRemoteCallElevatorDeviceId() != null && !bo.getRemoteCallElevatorDeviceId().isEmpty()) { - for (SisElevatorInfoBo.DeviceInfo deviceInfo : bo.getRemoteCallElevatorDeviceId()) { - SisDeviceBindRef ref = new SisDeviceBindRef(); - ref.setDeviceId(deviceInfo.getDeviceId()); - ref.setDeviceIp(deviceInfo.getDeviceIp()); - ref.setBindId(bo.getElevatorId()); - ref.setControlType(ControlTypeEnum.REMOTE_CALL_ELEVATOR.getCode()); - ls.add(ref); - } - } - // 写入绑定设备表 - if (!ls.isEmpty()) { - Boolean b = deviceBindRefService.batchInsert(ls); - Assert.isTrue(b, "设备绑定关联关系写入失败!"); - } + // 写入设备绑定关系 + this.insertSisDeviceBindRefs(bo); // 写入电梯⇄楼层⇄通道关联表 - if(!bo.getChannels().isEmpty()){ - Collection channelRefs = new ArrayList<>(); - for (SisElevatorInfoBo.ChannelInfo channelInfo : bo.getChannels()) { - SisElevatorFloorChannelRef ref = new SisElevatorFloorChannelRef(); - ref.setElevatorId(add.getElevatorId()); - ref.setFloorId(channelInfo.getFloorId()); - ref.setInChannel(channelInfo.getInChannel()); - ref.setOutChannel(channelInfo.getOutChannel()); - channelRefs.add(ref); - } - Boolean b = elevatorFloorChannelRefService.batchInsert(add.getElevatorId(), channelRefs); - Assert.isTrue(b, "电梯楼层通道关联关系写入失败!"); + if (!bo.getChannels().isEmpty()) { + this.insertSisElevatorFloorChannelRefs(bo); } - - // hik sdk 登录 -// short port = bo.getControlPort().shortValue(); -// Boolean isLogin = HikApiService.getInstance().login(bo.getControlIp(), port, bo.getControlAccount(), bo.getControlPwd()); -// Assert.isTrue(isLogin, "电梯添加失败, 发起梯控设备连接失败."); - // todo 发起电梯楼层信息同步 } return flag; } @@ -223,6 +185,19 @@ public class SisElevatorInfoServiceImpl implements ISisElevatorInfoService { // 删除设备绑定关系 deviceBindRefService.deleteByBindId(bo.getElevatorId()); // 重新写入关联关系 + this.insertSisDeviceBindRefs(bo); + + // 写入电梯⇄楼层⇄通道关联表 + if (!bo.getChannels().isEmpty()) { + this.insertSisElevatorFloorChannelRefs(bo); + } + return baseMapper.updateById(update) > 0; + } + + /** + * 抽取公共方法,写入绑定关系 + */ + private void insertSisDeviceBindRefs(SisElevatorInfoBo bo) { List ls = new ArrayList<>(); // 梯控 if (bo.getElevatorControlDeviceId() != null) { @@ -244,27 +219,34 @@ public class SisElevatorInfoServiceImpl implements ISisElevatorInfoService { ls.add(ref); } } + // 写入绑定设备表 if (!ls.isEmpty()) { Boolean b = deviceBindRefService.batchInsert(ls); Assert.isTrue(b, "设备绑定关联关系写入失败!"); } + } - // 写入电梯⇄楼层⇄通道关联表 - if(!bo.getChannels().isEmpty()){ - Collection channelRefs = new ArrayList<>(); - for (SisElevatorInfoBo.ChannelInfo channelInfo : bo.getChannels()) { - SisElevatorFloorChannelRef ref = new SisElevatorFloorChannelRef(); - ref.setElevatorId(update.getElevatorId()); - ref.setFloorId(channelInfo.getFloorId()); - ref.setInChannel(channelInfo.getInChannel()); - ref.setOutChannel(channelInfo.getOutChannel()); - channelRefs.add(ref); - } - Boolean b = elevatorFloorChannelRefService.batchInsert(update.getElevatorId(), channelRefs); - Assert.isTrue(b, "电梯楼层通道关联关系写入失败!"); + /** + * 抽取公共方法,写入电梯⇄楼层⇄通道关联 + */ + private void insertSisElevatorFloorChannelRefs(SisElevatorInfoBo bo) { + Collection channelRefs = new ArrayList<>(); + for (SisElevatorInfoBo.ChannelInfo channelInfo : bo.getChannels()) { + SisElevatorFloorChannelRef ref = new SisElevatorFloorChannelRef(); + ref.setElevatorId(bo.getElevatorId()); + ref.setFloorId(channelInfo.getFloorId()); + ref.setInChannel(channelInfo.getInChannel()); + ref.setOutChannel(channelInfo.getOutChannel()); + channelRefs.add(ref); } - return baseMapper.updateById(update) > 0; + // 写入电梯⇄楼层⇄通道关联表 + Boolean insert = elevatorFloorChannelRefService.batchInsert(bo.getElevatorId(), channelRefs); + Assert.isTrue(insert, "电梯⇄楼层⇄通道关联关系写入失败!"); + + // 冗余数据到电梯⇄楼层关联表 + Boolean update = elevatorFloorRefService.batchUpdateChannel(channelRefs); + } /**