refactor(sis): 1

This commit is contained in:
zcxlsm 2025-08-05 10:51:31 +08:00
parent 7c52b9b851
commit bbd895f116
7 changed files with 110 additions and 66 deletions

View File

@ -42,5 +42,15 @@ public class SisElevatorFloorRef extends TenantEntity {
*/
private Long authGroupId;
/**
* 内部通道号
*/
private Long inChannel;
/**
* 外部通道号
*/
private Long outChannel;
}

View File

@ -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<String, Object>
*/
Long findPerson(String base64Img);
Map<String, Object> findPerson(String base64Img);
}

View File

@ -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<String, Object> 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<String, Object> 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;
}
}

View File

@ -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<SisElevatorFloorRefVo> queryByAuthGroupId(Long authGroupId);
/**
* 批量更新电梯楼层通道关联信息
*
* @param info 通道信息
*/
Boolean batchUpdateChannel(Collection<SisElevatorFloorChannelRef> info);
}

View File

@ -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;

View File

@ -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<SisElevatorFloorChannelRef> info){
LambdaQueryWrapper<SisElevatorFloorRef> lqw = Wrappers.lambdaQuery();
lqw.in(SisElevatorFloorRef::getFloorId, info.stream().map(SisElevatorFloorChannelRef::getFloorId).toList());
List<SisElevatorFloorRef> list = baseMapper.selectList(lqw);
for (SisElevatorFloorRef item : list){
item.setInChannel(info.stream().filter(x -> x.getFloorId().equals(item.getFloorId())).findFirst().get().getInChannel());
}
return false;
}
}

View File

@ -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<SisDeviceBindRef> 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<SisElevatorFloorChannelRef> 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<SisDeviceBindRef> 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<SisElevatorFloorChannelRef> 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<SisElevatorFloorChannelRef> 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);
}
/**