|
|
@@ -35,6 +35,8 @@ public class RfidClientImpl implements IService {
|
|
|
private static final Map<String, GClient> clientMap = new ConcurrentHashMap<>();
|
|
|
private static final Map<String, GServer> serverMap = new ConcurrentHashMap<>();
|
|
|
private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
|
|
|
+ private static final Integer cacheTime = 30;
|
|
|
+ private static final Integer alarmTime = 30;
|
|
|
@Resource
|
|
|
private RedisTemplate<String, HardwareRfid> redisTemplate;
|
|
|
@Autowired
|
|
|
@@ -49,8 +51,11 @@ public class RfidClientImpl implements IService {
|
|
|
@Override
|
|
|
public void start(HardwareRfid hardwareRfid) {
|
|
|
GServer server = new GServer();
|
|
|
- int port = getPort(hardwareRfid.getIpAddress());
|
|
|
- if (server.open(port)) {
|
|
|
+ if (hardwareRfid.getPort() == null) {
|
|
|
+ log.info("【RFID门禁机】端口号为空!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (server.open(hardwareRfid.getPort())) {
|
|
|
log.info("【RFID门禁机】开始监听");
|
|
|
subscribeServerHandler(hardwareRfid, server);
|
|
|
} else {
|
|
|
@@ -155,18 +160,14 @@ public class RfidClientImpl implements IService {
|
|
|
int antId = logBaseEpcInfo.getAntId();
|
|
|
String epc = logBaseEpcInfo.getEpc();
|
|
|
if (Boolean.FALSE.equals(redisTemplate.hasKey(logBaseEpcInfo.getEpc() + antId))) {
|
|
|
- log.info("打印进入日志!");
|
|
|
//不存在缓存,设置间隔30s调用
|
|
|
- redisTemplate.opsForValue().set(logBaseEpcInfo.getEpc() + antId, hardwareRfid, 30, TimeUnit.SECONDS);
|
|
|
- log.info("打印进入日志!1111111111111");
|
|
|
+ redisTemplate.opsForValue().set(logBaseEpcInfo.getEpc() + antId, hardwareRfid, cacheTime, TimeUnit.SECONDS);
|
|
|
scheduledExecutorService.execute(() -> {
|
|
|
- log.info("打印日志发送前日志");
|
|
|
InventoryTag tag = new InventoryTag();
|
|
|
BeanUtils.copyProperties(logBaseEpcInfo, tag);
|
|
|
HardwareRfidDto hardwareRfidDto = new HardwareRfidDto();
|
|
|
BeanUtils.copyProperties(hardwareRfid, hardwareRfidDto);
|
|
|
tag.setHardwareRfidDto(hardwareRfidDto);
|
|
|
- log.info("调用发送方法!发送内容 tag = {}",tag.toString());
|
|
|
sendService.send(tag);
|
|
|
});
|
|
|
} else {
|
|
|
@@ -455,7 +456,7 @@ public class RfidClientImpl implements IService {
|
|
|
GClient client = clientMap.get(hardwareNum);
|
|
|
synchronized (this) {
|
|
|
//设置开始报警、报警时长
|
|
|
- return changeGpo(client, 1, 30);
|
|
|
+ return changeGpo(client, 1, alarmTime);
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
@@ -473,40 +474,4 @@ public class RfidClientImpl implements IService {
|
|
|
}
|
|
|
}, delayTime, TimeUnit.SECONDS);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 去掉端口号,只获取ip
|
|
|
- */
|
|
|
- private static String getIp(HardwareRfid hardwareRfid) {
|
|
|
- String ipAddress;
|
|
|
- if (Objects.isNull(hardwareRfid) || StringUtils.isBlank(hardwareRfid.getIpAddress())) {
|
|
|
- log.error("RFID配置ip为空!");
|
|
|
- }
|
|
|
- String[] ipPort = hardwareRfid.getIpAddress().split(":");
|
|
|
- if (ipPort.length > 1) {
|
|
|
- ipAddress = ipPort[0];
|
|
|
- } else {
|
|
|
- ipAddress = hardwareRfid.getIpAddress();
|
|
|
- }
|
|
|
- return ipAddress;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取端口号 未配置端口号默认给到8160
|
|
|
- *
|
|
|
- * @Param [ipPort]
|
|
|
- * @Return int
|
|
|
- **/
|
|
|
- private static int getPort(String ipPort) {
|
|
|
- //默认给到8160
|
|
|
- int port = 8160;
|
|
|
- if (null == ipPort || "".equals(ipPort)) {
|
|
|
- return port;
|
|
|
- }
|
|
|
- String[] split = ipPort.split(":");
|
|
|
- if (split.length > 1) {
|
|
|
- port = Integer.valueOf(split[1]);
|
|
|
- }
|
|
|
- return port;
|
|
|
- }
|
|
|
}
|