|
|
@@ -14,12 +14,12 @@ import com.usky.common.core.util.UUIDUtils;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.eg.domain.EgDevice;
|
|
|
import com.usky.eg.domain.EgDeviceHeartbeat;
|
|
|
-import com.usky.eg.domain.MeetingFace;
|
|
|
-import com.usky.eg.domain.MeetingFaceDevice;
|
|
|
+import com.usky.eg.domain.EgDevicePersonBind;
|
|
|
+import com.usky.eg.domain.EgRecord;
|
|
|
import com.usky.eg.mapper.EgDeviceMapper;
|
|
|
import com.usky.eg.mapper.EgDeviceHeartbeatMapper;
|
|
|
-import com.usky.eg.mapper.MeetingFaceDeviceMapper;
|
|
|
-import com.usky.eg.mapper.MeetingFaceMapper;
|
|
|
+import com.usky.eg.mapper.EgDevicePersonBindMapper;
|
|
|
+import com.usky.eg.mapper.EgRecordMapper;
|
|
|
import com.usky.eg.service.EgDeviceService;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import com.usky.eg.service.vo.EgDeviceRequestVO;
|
|
|
@@ -43,19 +43,18 @@ import java.util.concurrent.CompletableFuture;
|
|
|
*/
|
|
|
@Service
|
|
|
public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgDevice> implements EgDeviceService {
|
|
|
- @Autowired
|
|
|
- private MeetingFaceDeviceMapper meetingFaceDeviceMapper;
|
|
|
- @Autowired
|
|
|
- private MeetingFaceMapper meetingFaceMapper;
|
|
|
@Autowired
|
|
|
private EgDeviceMapper egDeviceMapper;
|
|
|
@Autowired
|
|
|
private EgDeviceHeartbeatMapper egDeviceHeartbeatMapper;
|
|
|
@Autowired
|
|
|
private RemoteIotTaskService remoteIotTaskService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private RemoteTransferService remoteTransferService;
|
|
|
+ @Autowired
|
|
|
+ private EgDevicePersonBindMapper egDevicePersonBindMapper;
|
|
|
+ @Autowired
|
|
|
+ private EgRecordMapper egRecordMapper;
|
|
|
|
|
|
@Override
|
|
|
public CommonPage<EgDevice> page(EgDeviceRequestVO requestVO){
|
|
|
@@ -95,6 +94,9 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
if (StringUtils.isNotBlank(deviceCode)) {
|
|
|
validDeviceCodes.add(deviceCode);
|
|
|
deviceCodeMap.put(deviceCode, device);
|
|
|
+ } else {
|
|
|
+ // deviceCode为空,直接设置为离线
|
|
|
+ device.setDeviceStatus(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -137,28 +139,11 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- LambdaQueryWrapper<MeetingFace> meetingFaceQuery = Wrappers.lambdaQuery();
|
|
|
- meetingFaceQuery.select(MeetingFace::getFid,MeetingFace::getCreateTime,MeetingFace::getVefNum,MeetingFace::getFaceName,MeetingFace::getRemark,MeetingFace::getFaceStatus,MeetingFace::getCardNum,MeetingFace::getBindDevice,MeetingFace::getDeptId,MeetingFace::getTenantId,MeetingFace::getUserId)
|
|
|
- .eq(MeetingFace::getTenantId,tenantId);
|
|
|
- List<MeetingFace> meetingAllFaceList = meetingFaceMapper.selectList(meetingFaceQuery);
|
|
|
-
|
|
|
- for (int i = 0; i < page.getRecords().size(); i++) {
|
|
|
- if(Objects.nonNull(page.getRecords().get(i).getBindFace()) ||StringUtils.isNotBlank(page.getRecords().get(i).getBindFace())){
|
|
|
- String[] fidListStr = page.getRecords().get(i).getBindFace().split(",");
|
|
|
- Integer[] fidList = Arrays.stream(fidListStr).map(Integer::parseInt).toArray(Integer[]::new);
|
|
|
-
|
|
|
- List<MeetingFace> meetingFaceList = new ArrayList<>();
|
|
|
- for (int j = 0; j < fidList.length; j++) {
|
|
|
- for (int k = 0; k < meetingAllFaceList.size(); k++) {
|
|
|
- if(fidList[j] == meetingAllFaceList.get(k).getFid()){
|
|
|
- meetingFaceList.add(meetingAllFaceList.get(k));
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- page.getRecords().get(i).setMeetingFaceList(meetingFaceList);
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询并填充绑定人员信息(来自 eg_device_person_bind,person_id 逗号分隔后写入 bindPerson 字段)
|
|
|
+ if (!page.getRecords().isEmpty()) {
|
|
|
+ fillBindPerson(page.getRecords());
|
|
|
}
|
|
|
|
|
|
return new CommonPage<>(page.getRecords(),page.getTotal(),requestVO.getSize(),requestVO.getCurrent());
|
|
|
@@ -167,29 +152,28 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
@Override
|
|
|
public CommonPage<EgDevice> wePage(EgDeviceRequestVO requestVO){
|
|
|
long userId = SecurityUtils.getUserId();
|
|
|
- //人员设备权限校验,校验通过,可以下发命令控制设备
|
|
|
- Integer fid = baseMapper.getMeetingFaceData(userId);
|
|
|
-// if(fid == null){
|
|
|
-// throw new BusinessException("人脸卡号信息未注册");
|
|
|
-// }
|
|
|
- Integer[] deviceFid = baseMapper.getMeetingFaceDeviceList(fid);
|
|
|
-// if(deviceFid.length == 0){
|
|
|
-// throw new BusinessException("人员未绑定设备,请检查");
|
|
|
-// }
|
|
|
+ // 通过 sys_user_person -> sys_person -> eg_device_person_bind -> eg_device 查询当前用户绑定的设备ID列表
|
|
|
+ List<Integer> deviceIds = egDevicePersonBindMapper.selectDeviceIdsByUserId(userId);
|
|
|
+ if (CollectionUtils.isEmpty(deviceIds)) {
|
|
|
+ // 未绑定任何设备,返回空分页
|
|
|
+ return new CommonPage<>(new ArrayList<>(), 0L, requestVO.getSize(), requestVO.getCurrent());
|
|
|
+ }
|
|
|
|
|
|
IPage<EgDevice> page = new Page<>(requestVO.getCurrent(),requestVO.getSize());
|
|
|
- if(deviceFid.length > 0){
|
|
|
- LambdaQueryWrapper<EgDevice> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.like(StringUtils.isNotBlank(requestVO.getDeviceName()),EgDevice::getDeviceName,requestVO.getDeviceName())
|
|
|
- .like(StringUtils.isNotBlank(requestVO.getInstallAddress()),EgDevice::getInstallAddress,requestVO.getInstallAddress())
|
|
|
- .eq(null != requestVO.getServiceStatus(),EgDevice::getServiceStatus,requestVO.getServiceStatus())
|
|
|
- .eq(null != requestVO.getId(),EgDevice::getId,requestVO.getId())
|
|
|
- .in(EgDevice::getId, (Object[]) deviceFid)
|
|
|
- .eq(EgDevice::getTenantId,SecurityUtils.getTenantId())
|
|
|
- .orderByDesc(EgDevice::getId);
|
|
|
- page = this.page(page,queryWrapper);
|
|
|
- }
|
|
|
+ LambdaQueryWrapper<EgDevice> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.like(StringUtils.isNotBlank(requestVO.getDeviceName()),EgDevice::getDeviceName,requestVO.getDeviceName())
|
|
|
+ .like(StringUtils.isNotBlank(requestVO.getInstallAddress()),EgDevice::getInstallAddress,requestVO.getInstallAddress())
|
|
|
+ .eq(null != requestVO.getServiceStatus(),EgDevice::getServiceStatus,requestVO.getServiceStatus())
|
|
|
+ .eq(null != requestVO.getId(),EgDevice::getId,requestVO.getId())
|
|
|
+ .in(EgDevice::getId, deviceIds)
|
|
|
+ .eq(EgDevice::getTenantId,SecurityUtils.getTenantId())
|
|
|
+ .orderByDesc(EgDevice::getId);
|
|
|
+ page = this.page(page,queryWrapper);
|
|
|
|
|
|
+ // 查询并填充绑定人员信息
|
|
|
+ if (!page.getRecords().isEmpty()) {
|
|
|
+ fillBindPerson(page.getRecords());
|
|
|
+ }
|
|
|
|
|
|
return new CommonPage<>(page.getRecords(),page.getTotal(),requestVO.getSize(),requestVO.getCurrent());
|
|
|
}
|
|
|
@@ -215,7 +199,18 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 3. 校验设备编码是否已被绑定
|
|
|
+ // 3. 若未传deviceCode但传了deviceIp,尝试从心跳表中获取deviceCode
|
|
|
+ if (StringUtils.isBlank(egDevice.getDeviceCode()) && StringUtils.isNotBlank(egDevice.getDeviceIp())) {
|
|
|
+ LambdaQueryWrapper<EgDeviceHeartbeat> heartbeatCheckWrapper = Wrappers.lambdaQuery();
|
|
|
+ heartbeatCheckWrapper.eq(EgDeviceHeartbeat::getIpAddr, egDevice.getDeviceIp())
|
|
|
+ .eq(EgDeviceHeartbeat::getDeviceStatus, 1);
|
|
|
+ EgDeviceHeartbeat heartbeat = egDeviceHeartbeatMapper.selectOne(heartbeatCheckWrapper);
|
|
|
+ if (heartbeat != null && StringUtils.isNotBlank(heartbeat.getDeviceCode())) {
|
|
|
+ egDevice.setDeviceCode(heartbeat.getDeviceCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 校验设备编码是否已被绑定
|
|
|
if (StringUtils.isNotBlank(egDevice.getDeviceCode())) {
|
|
|
LambdaQueryWrapper<EgDevice> codeCheckWrapper = Wrappers.lambdaQuery();
|
|
|
codeCheckWrapper.eq(EgDevice::getDeviceCode, egDevice.getDeviceCode())
|
|
|
@@ -227,7 +222,7 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 4. 设置设备基本信息
|
|
|
+ // 5. 设置设备基本信息
|
|
|
egDevice.setDeviceUuid(UUIDUtils.uuid());
|
|
|
egDevice.setCreateBy(SecurityUtils.getUsername());
|
|
|
egDevice.setCreateTime(now);
|
|
|
@@ -235,20 +230,9 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
egDevice.setOpenMode("人脸");
|
|
|
egDevice.setWorkStatus("4");
|
|
|
|
|
|
- // 5. 保存设备
|
|
|
+ // 6. 保存设备
|
|
|
this.save(egDevice);
|
|
|
|
|
|
- // 6. 处理绑定人脸信息
|
|
|
- String bindFace = egDevice.getBindFace();
|
|
|
- if (StringUtils.isNotBlank(bindFace)) {
|
|
|
- String[] fids = bindFace.split(",");
|
|
|
- for (String fid : fids) {
|
|
|
- if (StringUtils.isNotBlank(fid)) {
|
|
|
- egDeviceMapper.insertMeetingFaceDevice(Integer.parseInt(fid.trim()), egDevice.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// 7. 异步调用远程服务添加设备信息,静默处理异常,不影响设备保存成功
|
|
|
String deviceUuid = egDevice.getDeviceUuid();
|
|
|
String deviceName = egDevice.getDeviceName();
|
|
|
@@ -273,22 +257,6 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
|
|
|
@Override
|
|
|
public void update(EgDevice egDevice) {
|
|
|
-
|
|
|
- String[] fids = new String[0];
|
|
|
- if(Objects.nonNull(egDevice.getBindFace()) || StringUtils.isNotBlank(egDevice.getBindFace())){
|
|
|
- fids = egDevice.getBindFace().split(",");
|
|
|
-
|
|
|
- egDeviceMapper.deleteMeetingFaceDevice(egDevice.getId());
|
|
|
- }else{
|
|
|
- EgDevice one = this.getById(egDevice.getId());
|
|
|
- egDevice.setBindFace(one.getBindFace());
|
|
|
- }
|
|
|
- if(fids.length > 0){
|
|
|
- for (int i = 0; i < fids.length; i++) {
|
|
|
- egDeviceMapper.insertMeetingFaceDevice(Integer.parseInt(fids[i]),egDevice.getId());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
if(checkDeviceNameUnique(egDevice)){
|
|
|
throw new BusinessException("修改门禁设备'"+egDevice.getDeviceName()+"'失败,设备名称已存在");
|
|
|
}
|
|
|
@@ -306,6 +274,17 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 若未传deviceCode但传了deviceIp,尝试从心跳表中获取deviceCode
|
|
|
+ if (StringUtils.isBlank(egDevice.getDeviceCode()) && StringUtils.isNotBlank(egDevice.getDeviceIp())) {
|
|
|
+ LambdaQueryWrapper<EgDeviceHeartbeat> heartbeatCheckWrapper = Wrappers.lambdaQuery();
|
|
|
+ heartbeatCheckWrapper.eq(EgDeviceHeartbeat::getIpAddr, egDevice.getDeviceIp())
|
|
|
+ .eq(EgDeviceHeartbeat::getDeviceStatus, 1);
|
|
|
+ EgDeviceHeartbeat heartbeat = egDeviceHeartbeatMapper.selectOne(heartbeatCheckWrapper);
|
|
|
+ if (heartbeat != null && StringUtils.isNotBlank(heartbeat.getDeviceCode())) {
|
|
|
+ egDevice.setDeviceCode(heartbeat.getDeviceCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 校验设备编码是否已被其他设备绑定(排除当前设备)
|
|
|
if (StringUtils.isNotBlank(egDevice.getDeviceCode())) {
|
|
|
LambdaQueryWrapper<EgDevice> codeCheckWrapper = Wrappers.lambdaQuery();
|
|
|
@@ -347,10 +326,9 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
EgDevice egDevice = this.getById(id);
|
|
|
Optional.ofNullable(egDevice).orElseThrow(() -> new BusinessException("门禁设备信息不存在"));
|
|
|
|
|
|
- LambdaQueryWrapper<MeetingFaceDevice> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.eq(MeetingFaceDevice::getDeviceId,id);
|
|
|
- Integer count = meetingFaceDeviceMapper.selectCount(queryWrapper);
|
|
|
- if(count > 0){
|
|
|
+ // 校验 eg_device_person_bind 是否存在绑定人员
|
|
|
+ Integer personBindCount = egDevicePersonBindMapper.countByDeviceId(id);
|
|
|
+ if (personBindCount != null && personBindCount > 0) {
|
|
|
throw new BusinessException("已绑定人员不能删除");
|
|
|
}
|
|
|
|
|
|
@@ -369,6 +347,53 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据设备ID集合查询 eg_device_person_bind,将 person_id 按逗号拼接后写入设备的 bindPerson 字段
|
|
|
+ */
|
|
|
+ private void fillBindPerson(List<EgDevice> devices) {
|
|
|
+ if (CollectionUtils.isEmpty(devices)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Integer> deviceIds = new ArrayList<>();
|
|
|
+ for (EgDevice device : devices) {
|
|
|
+ if (device != null && device.getId() != null) {
|
|
|
+ deviceIds.add(device.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (deviceIds.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<EgDevicePersonBind> bindList = egDevicePersonBindMapper.selectByDeviceIds(deviceIds);
|
|
|
+ if (CollectionUtils.isEmpty(bindList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Integer, List<String>> devicePersonMap = new HashMap<>();
|
|
|
+ for (EgDevicePersonBind bind : bindList) {
|
|
|
+ if (bind.getDeviceId() == null || bind.getPersonId() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ devicePersonMap
|
|
|
+ .computeIfAbsent(bind.getDeviceId(), k -> new ArrayList<>())
|
|
|
+ .add(String.valueOf(bind.getPersonId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (EgDevice device : devices) {
|
|
|
+ if (device == null || device.getId() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> personIds = devicePersonMap.get(device.getId());
|
|
|
+ if (personIds != null && !personIds.isEmpty()) {
|
|
|
+ device.setBindPerson(String.join(",", personIds));
|
|
|
+ } else {
|
|
|
+ device.setBindPerson(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean checkNameUnique(EgDevice egDevice){
|
|
|
Integer id = null == egDevice.getId() ? -1 : egDevice.getId();
|
|
|
@@ -390,60 +415,100 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String,Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName, Integer categoryType, String gatewayUuid){
|
|
|
- Integer tenantId;
|
|
|
- long commandUserId;
|
|
|
- String commandUserName;
|
|
|
- EgDevice device = null;
|
|
|
-
|
|
|
- // 通过deviceUuid查询设备获取tenantId
|
|
|
- if(StringUtils.isNotBlank(deviceUuid)){
|
|
|
- LambdaQueryWrapper<EgDevice> deviceQueryWrapper = Wrappers.lambdaQuery();
|
|
|
- deviceQueryWrapper.select(EgDevice::getId, EgDevice::getTenantId)
|
|
|
- .eq(EgDevice::getDeviceUuid, deviceUuid);
|
|
|
- device = this.getOne(deviceQueryWrapper);
|
|
|
- if(device != null){
|
|
|
- tenantId = device.getTenantId();
|
|
|
- commandUserId = userId;
|
|
|
- commandUserName = userName;
|
|
|
- }else{
|
|
|
- throw new BusinessException("设备未注册,请先注册");
|
|
|
- }
|
|
|
- }else{
|
|
|
- tenantId = SecurityUtils.getTenantId();
|
|
|
- commandUserId = SecurityUtils.getUserId();
|
|
|
- commandUserName = SecurityUtils.getUsername();
|
|
|
+ public Map<String,Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, Long userId, String userName, Integer categoryType, String gatewayUuid, Boolean skipCheck, Integer passType){
|
|
|
+ // 1. 查询设备
|
|
|
+ EgDevice device = this.getOne(Wrappers.<EgDevice>lambdaQuery()
|
|
|
+ .select(EgDevice::getId, EgDevice::getTenantId)
|
|
|
+ .eq(EgDevice::getDeviceUuid, deviceUuid));
|
|
|
+ if (device == null) {
|
|
|
+ throw new BusinessException("设备未注册,请先注册");
|
|
|
}
|
|
|
|
|
|
- //人员设备权限校验,校验通过,可以下发命令控制设备
|
|
|
- if(device != null){
|
|
|
- Integer fid = baseMapper.getMeetingFaceData(commandUserId);
|
|
|
- if(fid == null){
|
|
|
- throw new BusinessException("人脸卡号信息未注册");
|
|
|
- }
|
|
|
- Integer[] deviceFid = baseMapper.getMeetingFaceDeviceList(fid);
|
|
|
- if(deviceFid.length == 0){
|
|
|
- throw new BusinessException("人员未绑定设备,请检查");
|
|
|
- }
|
|
|
-
|
|
|
- boolean exist = Arrays.asList(deviceFid).contains(device.getId());
|
|
|
- if(!exist){
|
|
|
+ Integer tenantId = device.getTenantId();
|
|
|
+ long commandUserId = userId != null ? userId : SecurityUtils.getUserId();
|
|
|
+ String commandUserName = userName != null ? userName : SecurityUtils.getUsername();
|
|
|
+
|
|
|
+ // 2. 权限校验
|
|
|
+ if (!Boolean.TRUE.equals(skipCheck)) {
|
|
|
+ Integer bindCount = egDevicePersonBindMapper.countByUserIdAndDeviceId(commandUserId, device.getId());
|
|
|
+ if (bindCount == null || bindCount == 0) {
|
|
|
+ saveRecord(device.getId(), tenantId, commandUserName, passType, "失败:暂无权限");
|
|
|
throw new BusinessException("暂无权限");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 3. 构建下发命令参数
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+ params.put("commandCode", commandCode);
|
|
|
+ params.put("commandValue", commandValue);
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
- map.put("method","control");
|
|
|
+ map.put("method", "control");
|
|
|
map.put("deviceUuid", deviceUuid);
|
|
|
- Map<String,Object> map1 = new HashMap<>();
|
|
|
- map1.put("commandCode",commandCode);
|
|
|
- map1.put("commandValue",commandValue);
|
|
|
- map.put("params",map1);
|
|
|
+ map.put("params", params);
|
|
|
+
|
|
|
+ // 4. 下发命令并记录结果
|
|
|
+ String targetUuid = categoryType == 3 ? gatewayUuid : deviceUuid;
|
|
|
+ Map<String,Object> result = null;
|
|
|
+ String passResult = "下发命令失败";
|
|
|
+ try {
|
|
|
+ result = remoteTransferService.deviceControl(productCode, targetUuid, JSON.toJSONString(map), tenantId, commandUserId, commandUserName);
|
|
|
+ if (result == null || !Integer.valueOf(200).equals(result.get("code"))) {
|
|
|
+ passResult = result != null && result.get("message") != null ? result.get("message").toString() : "下发命令失败";
|
|
|
+ throw new BusinessException(passResult);
|
|
|
+ }
|
|
|
+ passResult = result.get("message") != null ? result.get("message").toString() : "下发命令成功";
|
|
|
+ return result;
|
|
|
+ } finally {
|
|
|
+ saveRecord(device.getId(), tenantId, commandUserName, passType, passResult);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if(categoryType == 3){
|
|
|
- return remoteTransferService.deviceControl(productCode, gatewayUuid, JSON.toJSONString(map), tenantId, commandUserId, commandUserName);
|
|
|
- }else{
|
|
|
- return remoteTransferService.deviceControl(productCode, deviceUuid, JSON.toJSONString(map), tenantId, commandUserId, commandUserName);
|
|
|
+ /**
|
|
|
+ * 插入通行记录,失败不影响主流程
|
|
|
+ */
|
|
|
+ private void saveRecord(Integer deviceId, Integer tenantId, String userName, Integer passType, String passResult) {
|
|
|
+ try {
|
|
|
+ EgRecord record = new EgRecord();
|
|
|
+ record.setEgDeviceId(deviceId);
|
|
|
+ record.setTenantId(tenantId);
|
|
|
+ record.setPassTime(LocalDateTime.now());
|
|
|
+ record.setCreateTime(LocalDateTime.now());
|
|
|
+ record.setPassResult(passResult);
|
|
|
+ record.setUserName(userName);
|
|
|
+ record.setPassType(passType);
|
|
|
+ egRecordMapper.insert(record);
|
|
|
+ } catch (Exception ignored) {}
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void bindPerson(Integer deviceId, String personIds, Integer isLoginNotify) {
|
|
|
+ if (deviceId == null) {
|
|
|
+ throw new BusinessException("设备ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先校验设备是否存在
|
|
|
+ EgDevice device = this.getById(deviceId);
|
|
|
+ Optional.ofNullable(device).orElseThrow(() -> new BusinessException("门禁设备信息不存在"));
|
|
|
+
|
|
|
+ // 先清空原有绑定关系
|
|
|
+ egDevicePersonBindMapper.deleteByDeviceId(deviceId);
|
|
|
+
|
|
|
+ // 为空则视为解绑所有人员
|
|
|
+ if (!StringUtils.isNotBlank(personIds)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] personIdArr = personIds.split(",");
|
|
|
+ int loginNotify = (isLoginNotify == null) ? 0 : isLoginNotify;
|
|
|
+ for (String personIdStr : personIdArr) {
|
|
|
+ if (!StringUtils.isNotBlank(personIdStr)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ EgDevicePersonBind bind = new EgDevicePersonBind();
|
|
|
+ bind.setDeviceId(deviceId);
|
|
|
+ bind.setPersonId(Integer.parseInt(personIdStr.trim()));
|
|
|
+ bind.setIsLoginNotify(loginNotify);
|
|
|
+ egDevicePersonBindMapper.insert(bind);
|
|
|
}
|
|
|
}
|
|
|
}
|