|
|
@@ -3,6 +3,7 @@ package org.dromara.server.hik.service.impl;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -109,7 +110,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
Long factoryId = accountVo.getFactoryId();
|
|
|
setCardToEmpInfoDto(empDto, factoryId, deleteAllCard, deleteCard);
|
|
|
|
|
|
- if(uploadPhoto){
|
|
|
+ if (uploadPhoto) {
|
|
|
// 设置用户人脸图片信息
|
|
|
String photo = accountVo.getFacePicUrl();
|
|
|
setPhotoToEmpInfoDto(empDto, photo, deleteAllFace, deleteFace);
|
|
|
@@ -119,7 +120,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private static EmpInfoDto createEmpInfoDto(@NotNull RemoteUserAccountVo accountVo,Boolean deleteUser) {
|
|
|
+ private static EmpInfoDto createEmpInfoDto(@NotNull RemoteUserAccountVo accountVo, Boolean deleteUser) {
|
|
|
EmpInfoDto empDto = new EmpInfoDto();
|
|
|
// 设置用户基本信息
|
|
|
empDto.setEmployeeNo(accountVo.getUserNo().toString()).setName(accountVo.getRealName());
|
|
|
@@ -138,7 +139,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
}
|
|
|
|
|
|
// 更新人脸
|
|
|
- private static void setPhotoToEmpInfoDto(EmpInfoDto empDto,String photo,Boolean deleteAllFace, Boolean deleteFace) {
|
|
|
+ private static void setPhotoToEmpInfoDto(EmpInfoDto empDto, String photo, Boolean deleteAllFace, Boolean deleteFace) {
|
|
|
if (ObjectUtil.isNotEmpty(photo)) {
|
|
|
FaceDto faceDto = new FaceDto().setFDID("1").setFaceID(1L).setFacePicURL(photo);
|
|
|
faceDto.setDeleteFace(deleteFace);
|
|
|
@@ -153,12 +154,17 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
}
|
|
|
|
|
|
// 更新卡片
|
|
|
- private static void setCardToEmpInfoDto(EmpInfoDto empDto,Long factoryId,Boolean deleteAllCard, Boolean deleteCard) {
|
|
|
+ private static void setCardToEmpInfoDto(EmpInfoDto empDto, Long factoryId, Boolean deleteAllCard, Boolean deleteCard) {
|
|
|
CardListDto cardListDto = new CardListDto();
|
|
|
// 更新卡片时deleteAllCard为true,保证最多只有一张卡,其实固定为true就好
|
|
|
cardListDto.setDeleteAllCard(deleteAllCard);
|
|
|
if (ObjectUtil.isNotEmpty(factoryId) && factoryId > 0L) {
|
|
|
- CardDto cardDto = new CardDto().setCardNo(factoryId.toString());
|
|
|
+ String s = factoryId.toString();
|
|
|
+ if (s.length() < 10) {
|
|
|
+ s = StrUtil.padPre(s,10,'0');
|
|
|
+ }
|
|
|
+ //CardDto cardDto = new CardDto().setCardNo(factoryId.toString());
|
|
|
+ CardDto cardDto = new CardDto().setCardNo(s);
|
|
|
cardDto.setDeleteCard(deleteCard);
|
|
|
|
|
|
List<CardDto> cardList = new ArrayList<>();
|
|
|
@@ -183,7 +189,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
}
|
|
|
|
|
|
@NotNull
|
|
|
- private DeviceDto getDeviceDto(@NotNull XfTermVo termVo) {
|
|
|
+ private DeviceDto getDeviceDto(@NotNull XfTermVo termVo) {
|
|
|
return getDeviceDto(termVo.getTermNo(), termVo.getAdminName(), termVo.getAdminPwd(), termVo.getTermIp(),
|
|
|
termVo.getCommPort(), termVo.getServerIp(), termVo.getServerPort());
|
|
|
}
|
|
|
@@ -196,7 +202,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
dto.setAdminPwd(adminPwd);
|
|
|
// 如果配置了映射IP,则使用映射IP
|
|
|
boolean hasCommonIp = StringUtils.isNotBlank(commonIP);
|
|
|
- dto.setDeviceIp(hasCommonIp ? commonIP :termIp);
|
|
|
+ dto.setDeviceIp(hasCommonIp ? commonIP : termIp);
|
|
|
// 海康设备的端口 都是80
|
|
|
dto.setDevicePort(hasCommonIp ? commPort.intValue() : 80);
|
|
|
dto.setServerIp(serverIp);
|
|
|
@@ -226,28 +232,28 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
*/
|
|
|
private String createHostXml(@NotNull DeviceDto dto) {
|
|
|
String xmlTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
|
|
- "<HttpHostNotification version=\"2.0\"\n" +
|
|
|
- " xmlns=\"http://www.isapi.org/ver20/XMLSchema\">\n" +
|
|
|
- " <id>1</id>\n" +
|
|
|
- " <url>{}</url>\n" +
|
|
|
- " <protocolType>HTTP</protocolType>\n" +
|
|
|
- " <parameterFormatType>XML</parameterFormatType>\n" +
|
|
|
- " <addressingFormatType>ipaddress</addressingFormatType>\n" +
|
|
|
- " <ipAddress>{}</ipAddress>\n" +
|
|
|
- " <portNo>{}</portNo>\n" +
|
|
|
- " <httpAuthenticationMethod>none</httpAuthenticationMethod>\n" +
|
|
|
- " <SubscribeEvent>\n" +
|
|
|
- " <heartbeat>30</heartbeat>\n" +
|
|
|
- " <eventMode>list</eventMode>\n" +
|
|
|
- " <EventList>\n" +
|
|
|
- " <Event>\n" +
|
|
|
- " <type>ConsumptionAndTransactionRecordEvent</type>\n" +
|
|
|
- " </Event>\n" +
|
|
|
- " </EventList>\n" +
|
|
|
- " </SubscribeEvent>\n" +
|
|
|
- "</HttpHostNotification>\n";
|
|
|
-
|
|
|
- return StringUtils.format(xmlTemplate,dto.getServerUrl(), dto.getServerIp(), dto.getServerPort());
|
|
|
+ "<HttpHostNotification version=\"2.0\"\n" +
|
|
|
+ " xmlns=\"http://www.isapi.org/ver20/XMLSchema\">\n" +
|
|
|
+ " <id>1</id>\n" +
|
|
|
+ " <url>{}</url>\n" +
|
|
|
+ " <protocolType>HTTP</protocolType>\n" +
|
|
|
+ " <parameterFormatType>XML</parameterFormatType>\n" +
|
|
|
+ " <addressingFormatType>ipaddress</addressingFormatType>\n" +
|
|
|
+ " <ipAddress>{}</ipAddress>\n" +
|
|
|
+ " <portNo>{}</portNo>\n" +
|
|
|
+ " <httpAuthenticationMethod>none</httpAuthenticationMethod>\n" +
|
|
|
+ " <SubscribeEvent>\n" +
|
|
|
+ " <heartbeat>30</heartbeat>\n" +
|
|
|
+ " <eventMode>list</eventMode>\n" +
|
|
|
+ " <EventList>\n" +
|
|
|
+ " <Event>\n" +
|
|
|
+ " <type>ConsumptionAndTransactionRecordEvent</type>\n" +
|
|
|
+ " </Event>\n" +
|
|
|
+ " </EventList>\n" +
|
|
|
+ " </SubscribeEvent>\n" +
|
|
|
+ "</HttpHostNotification>\n";
|
|
|
+
|
|
|
+ return StringUtils.format(xmlTemplate, dto.getServerUrl(), dto.getServerIp(), dto.getServerPort());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -280,7 +286,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
</HttpHostNotification>
|
|
|
""";
|
|
|
|
|
|
- return StringUtils.format(xmlTemplate,dto.getServerUrl(), dto.getServerIp());
|
|
|
+ return StringUtils.format(xmlTemplate, dto.getServerUrl(), dto.getServerIp());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -305,7 +311,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
|
|
|
// 格式化时间
|
|
|
String nowTime = now.format(formatter);
|
|
|
- return StringUtils.format(xmlTemplate,nowTime);
|
|
|
+ return StringUtils.format(xmlTemplate, nowTime);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -450,19 +456,19 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
if (R.isError(check)) {
|
|
|
return R.fail(
|
|
|
MessageFormat.format("[上传人员信息失败]-[设备IP:{0}, 人员信息:{1}, 错误信息:{2}", device.getDeviceIp(), empInfo,
|
|
|
- check.getMsg()));
|
|
|
+ check.getMsg()));
|
|
|
}
|
|
|
check = this.validStatusCodeException(sendResult);
|
|
|
if (R.isError(check)) {
|
|
|
return R.fail(
|
|
|
MessageFormat.format("[上传人员信息失败]-[设备IP:{0}, 人员信息:{1}, 错误信息:{2}", device.getDeviceIp(), empInfo,
|
|
|
- check.getMsg()));
|
|
|
+ check.getMsg()));
|
|
|
}
|
|
|
check = this.validDetailInfo(sendResult);
|
|
|
if (R.isError(check)) {
|
|
|
return R.fail(
|
|
|
MessageFormat.format("[上传人员信息失败]-[设备IP:{0}, 人员信息:{1}, 错误信息:{2}", device.getDeviceIp(), empInfo,
|
|
|
- check.getMsg()));
|
|
|
+ check.getMsg()));
|
|
|
}
|
|
|
return R.ok(MessageFormat.format("[上传人员信息成功]-[设备IP:{0}, 人员信息:{1}]", device.getDeviceIp(), empInfo));
|
|
|
}
|
|
|
@@ -499,17 +505,17 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
List<Long> onlineDeviceList = getOnlineDeviceList();
|
|
|
//只给在线设备下发数据
|
|
|
List<RemoteXfTermVo> list = termList.stream().filter(p -> onlineDeviceList.contains(p.getTermNo())).toList();
|
|
|
- if(CollectionUtil.isEmpty(list)){
|
|
|
+ if (CollectionUtil.isEmpty(list)) {
|
|
|
log.info("没有在线设备");
|
|
|
return;
|
|
|
}
|
|
|
threadPoolTaskExecutor.execute(() -> list.forEach(p -> {
|
|
|
- try{
|
|
|
+ try {
|
|
|
DeviceDto deviceDto = getDeviceDto(p);
|
|
|
this.createOperatorEmpInfo(deviceDto, empDto);
|
|
|
// log.info(result.getMsg());
|
|
|
- }catch (Exception e){
|
|
|
- log.error("下发数据失败:{}, 机号:{}",e.getMessage(), p.getTermNo());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("下发数据失败:{}, 机号:{}", e.getMessage(), p.getTermNo());
|
|
|
}
|
|
|
}));
|
|
|
|
|
|
@@ -529,7 +535,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
return R.fail("监听端口不能为空");
|
|
|
}
|
|
|
|
|
|
- if(ObjectUtil.isEmpty(dto.getServerUrl())){
|
|
|
+ if (ObjectUtil.isEmpty(dto.getServerUrl())) {
|
|
|
dto.setServerUrl(listenUrl);
|
|
|
}
|
|
|
String setData = this.createHostXml(dto);
|
|
|
@@ -587,7 +593,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
}
|
|
|
List<RemoteXfTermVo> list = termList.stream().filter(p -> onlineDeviceList.contains(p.getTermNo())).toList();
|
|
|
list.forEach(p -> threadPoolTaskExecutor.execute(() -> {
|
|
|
- try{
|
|
|
+ try {
|
|
|
DeviceDto dto = getDeviceDto(p);
|
|
|
R<Void> result = syncTimeToDevice(dto);
|
|
|
log.info(result.getMsg());
|
|
|
@@ -600,8 +606,9 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
|
|
|
/**
|
|
|
* 同步时间到设备
|
|
|
+ *
|
|
|
* @param device 设备信息
|
|
|
- * @return R
|
|
|
+ * @return R
|
|
|
*/
|
|
|
private R<Void> syncTimeToDevice(DeviceDto device) {
|
|
|
String setData = createTimeXml();
|
|
|
@@ -611,13 +618,13 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
Integer termNo = device.getTermNo();
|
|
|
String requestUrl = StringUtils.format("http://{}:{}{}", device.getDeviceIp(), device.getDevicePort(), HikApiConstants.SYNC_TIME_URL);
|
|
|
JSONObject sendResult = digestHttpUtil.sendPut(setData, requestUrl, ContentTypeEnum.XML.getCode(), device.getAdminName(), device.getAdminPwd());
|
|
|
- if(sendResult == null){
|
|
|
+ if (sendResult == null) {
|
|
|
// log.error("同步时间失败,设备无返回,设备号:{}", termNo);
|
|
|
- return R.fail("同步时间失败,设备无返回,设备号:"+ termNo);
|
|
|
+ return R.fail("同步时间失败,设备无返回,设备号:" + termNo);
|
|
|
}
|
|
|
if (ObjectUtil.isEmpty(sendResult.getObj("ResponseStatus"))) {
|
|
|
// log.error("同步时间失败,设备返回格式异常,设备号:{}", termNo);
|
|
|
- return R.fail("同步时间失败,设备返回格式异常,设备号:"+ termNo);
|
|
|
+ return R.fail("同步时间失败,设备返回格式异常,设备号:" + termNo);
|
|
|
}
|
|
|
JSONObject responseStatus = sendResult.getJSONObject("ResponseStatus");
|
|
|
Integer statusCode = responseStatus.getInt("statusCode");
|
|
|
@@ -626,7 +633,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
// log.error("同步时间失败,设备返回错误码:{}{},设备号:{}", statusCode,message, termNo);
|
|
|
return R.fail(message);
|
|
|
}
|
|
|
- return R.ok("同步时间成功,设备号:"+ termNo);
|
|
|
+ return R.ok("同步时间成功,设备号:" + termNo);
|
|
|
}
|
|
|
|
|
|
// region 从消费机删除人员相关
|
|
|
@@ -752,7 +759,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
@Override
|
|
|
public R<Void> deleteAllCardByUserId(Long userId) {
|
|
|
RemoteUserAccountVo byId = remoteUserAccountService.getById(userId);
|
|
|
- if(byId == null){
|
|
|
+ if (byId == null) {
|
|
|
return R.fail("未找到该用户");
|
|
|
}
|
|
|
// 获取所有设备
|
|
|
@@ -760,7 +767,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
if (CollectionUtil.isEmpty(termList)) {
|
|
|
return R.warn("没有要处理人员的设备");
|
|
|
}
|
|
|
- EmpInfoDto empDto = getEmpInfoDto(byId, false, false, false, true, false,false);
|
|
|
+ EmpInfoDto empDto = getEmpInfoDto(byId, false, false, false, true, false, false);
|
|
|
|
|
|
sendEmpToAllDevice(empDto);
|
|
|
return R.ok();
|
|
|
@@ -833,7 +840,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
try {//如果过了有效期,则直接删除 deleteUser为true
|
|
|
ResultBoolean obtainBoolean = getResult(p);
|
|
|
// deleteAllCard为true 保证只有一张卡片
|
|
|
- EmpInfoDto empDto = getEmpInfoDto(p, obtainBoolean.deleteUser(), obtainBoolean.deleteAllFace(), obtainBoolean.deleteFace(), obtainBoolean.deleteAllCard(), obtainBoolean.deleteCard(),true);
|
|
|
+ EmpInfoDto empDto = getEmpInfoDto(p, obtainBoolean.deleteUser(), obtainBoolean.deleteAllFace(), obtainBoolean.deleteFace(), obtainBoolean.deleteAllCard(), obtainBoolean.deleteCard(), true);
|
|
|
R<Void> result = createOperatorEmpInfo(deviceDto, empDto);
|
|
|
log.info(result.getMsg());
|
|
|
} catch (Exception e) {
|
|
|
@@ -847,9 +854,9 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
@NotNull
|
|
|
private static ResultBoolean getResult(RemoteUserAccountVo p) {
|
|
|
boolean deleteUser = false;
|
|
|
- if(p.getLifespan()!=null){
|
|
|
+ if (p.getLifespan() != null) {
|
|
|
//如果lifespan比当前时间小或者非开户的,则设置deleteUser为true
|
|
|
- if(p.getLifespan().getTime()<System.currentTimeMillis()){
|
|
|
+ if (p.getLifespan().getTime() < System.currentTimeMillis()) {
|
|
|
deleteUser = true;
|
|
|
}
|
|
|
}
|
|
|
@@ -859,7 +866,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
// 如果 照片不为空,deleteAllFace为true,deleteFace为false
|
|
|
boolean deleteAllFace = false;
|
|
|
boolean deleteFace = false;
|
|
|
- if(StringUtils.isNotBlank(p.getPhoto())){
|
|
|
+ if (StringUtils.isNotBlank(p.getPhoto())) {
|
|
|
deleteAllFace = true;
|
|
|
}
|
|
|
// 如果 factoryId 不为空且cardStatus 为 1,deleteAllCard为true,deleteCard为false,否则 deleteAllCard为false,deleteCard为true
|
|
|
@@ -867,9 +874,9 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
boolean deleteCard = false;
|
|
|
Long factoryId = p.getFactoryId();
|
|
|
String cardStatus = p.getCardStatus();
|
|
|
- if(Objects.nonNull(factoryId)&& factoryId!=0){
|
|
|
+ if (Objects.nonNull(factoryId) && factoryId != 0) {
|
|
|
deleteAllCard = true;
|
|
|
- if(StringUtils.isNotBlank(cardStatus) && !CardStatusEnum.NORMAL.code().toString().equals(cardStatus)){
|
|
|
+ if (StringUtils.isNotBlank(cardStatus) && !CardStatusEnum.NORMAL.code().toString().equals(cardStatus)) {
|
|
|
deleteAllCard = false;
|
|
|
//其他状态的卡直接删除
|
|
|
deleteCard = true;
|
|
|
@@ -882,7 +889,8 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
return new ResultBoolean(deleteUser, deleteAllFace, deleteFace, deleteAllCard, deleteCard);
|
|
|
}
|
|
|
|
|
|
- private record ResultBoolean(boolean deleteUser, boolean deleteAllFace, boolean deleteFace, boolean deleteAllCard, boolean deleteCard) {
|
|
|
+ private record ResultBoolean(boolean deleteUser, boolean deleteAllFace, boolean deleteFace, boolean deleteAllCard,
|
|
|
+ boolean deleteCard) {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -891,13 +899,14 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
|
|
|
RemoteUserAccountVo accountVo = remoteUserAccountService.getUserAccountVoBy(userId);
|
|
|
|
|
|
- EmpInfoDto empDto = getEmpInfoDto(accountVo, false, false, false, true, false,true);
|
|
|
+ EmpInfoDto empDto = getEmpInfoDto(accountVo, false, false, false, true, false, true);
|
|
|
|
|
|
return this.createOperatorEmpInfo(deviceDto, empDto);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 暂不使用,不能一次上传所有用户到所有设备上
|
|
|
+ * 暂不使用,不能一次上传所有用户到所有设备上
|
|
|
+ *
|
|
|
* @param uploadPhoto
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -918,8 +927,8 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
termList.forEach(p -> {
|
|
|
DeviceDto device = getDeviceDto(p);
|
|
|
accountVoList.forEach(t -> {
|
|
|
- threadPoolTaskExecutor.execute(()->{
|
|
|
- EmpInfoDto empInfo = getEmpInfoDto(t, false, false, false, true, false,uploadPhoto);
|
|
|
+ threadPoolTaskExecutor.execute(() -> {
|
|
|
+ EmpInfoDto empInfo = getEmpInfoDto(t, false, false, false, true, false, uploadPhoto);
|
|
|
R<Void> result = createOperatorEmpInfo(device, empInfo);
|
|
|
log.info(result.getMsg());
|
|
|
});
|
|
|
@@ -931,12 +940,12 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
/**
|
|
|
* 上传days内的数据至指定mac设备
|
|
|
*
|
|
|
- * @param startDate 天数
|
|
|
+ * @param startDate 天数
|
|
|
* @param uploadPhoto 是否上传照片
|
|
|
* @return 无
|
|
|
*/
|
|
|
@Override
|
|
|
- public R<Void> upLoadEmpToDevice(String macAddress,Date startDate, Boolean uploadPhoto) {
|
|
|
+ public R<Void> upLoadEmpToDevice(String macAddress, Date startDate, Boolean uploadPhoto) {
|
|
|
List<RemoteUserAccountVo> vos = remoteUserAccountService.getUpdateUserAccountVo(startDate);
|
|
|
if (CollectionUtil.isEmpty(vos)) {
|
|
|
log.info("heartBeat没有要处理人员数据");
|
|
|
@@ -948,14 +957,14 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
return R.warn(MessageFormat.format("设备未找到,mac:{0}", macAddress));
|
|
|
}
|
|
|
DeviceDto device = getDeviceDto(termVo);
|
|
|
- threadPoolTaskExecutor.execute(()-> vos.forEach(t -> {
|
|
|
- try{
|
|
|
+ threadPoolTaskExecutor.execute(() -> vos.forEach(t -> {
|
|
|
+ try {
|
|
|
ResultBoolean obtainBoolean = getResult(t);
|
|
|
EmpInfoDto empInfo = getEmpInfoDto(t, obtainBoolean.deleteUser(), obtainBoolean.deleteAllFace(),
|
|
|
- obtainBoolean.deleteFace(), obtainBoolean.deleteAllCard(), obtainBoolean.deleteCard(),uploadPhoto);
|
|
|
+ obtainBoolean.deleteFace(), obtainBoolean.deleteAllCard(), obtainBoolean.deleteCard(), uploadPhoto);
|
|
|
R<Void> result = createOperatorEmpInfo(device, empInfo);
|
|
|
log.info(result.getMsg());
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error("heartBeat下发人员{}异常: {}", t.getUserId(), e.getMessage(), e);
|
|
|
}
|
|
|
@@ -971,7 +980,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
return R.warn(MessageFormat.format("没有要处理的人员信息,userId:{0}", userId));
|
|
|
}
|
|
|
//保持只有一张卡 deleteAllCard为true,deleteCard为false
|
|
|
- EmpInfoDto empDto = getEmpInfoDto(accountVo, false, false, false, true, false,true);
|
|
|
+ EmpInfoDto empDto = getEmpInfoDto(accountVo, false, false, false, true, false, true);
|
|
|
|
|
|
sendEmpToAllDevice(empDto);
|
|
|
|
|
|
@@ -979,7 +988,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R<Void> upLoadEmpToAllDeviceByUserNo(Long userNo,String name, Date lifeSpan, Boolean deleteUser) {
|
|
|
+ public R<Void> upLoadEmpToAllDeviceByUserNo(Long userNo, String name, Date lifeSpan, Boolean deleteUser) {
|
|
|
RemoteUserAccountVo accountVo = new RemoteUserAccountVo();
|
|
|
accountVo.setUserNo(userNo);
|
|
|
accountVo.setLifespan(lifeSpan);
|
|
|
@@ -1031,9 +1040,10 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
|
|
|
/**
|
|
|
* 删除账户时下发数据
|
|
|
+ *
|
|
|
* @param userId
|
|
|
*/
|
|
|
- public void whenDeleteSend(Long userId){
|
|
|
+ public void whenDeleteSend(Long userId) {
|
|
|
RemoteUserAccountVo accountVo = remoteUserAccountService.getById(userId);
|
|
|
if (ObjectUtil.isEmpty(accountVo)) {
|
|
|
R.warn(MessageFormat.format("没有要处理的人员信息,userId:{0}", userId));
|
|
|
@@ -1051,7 +1061,7 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
* @param userId
|
|
|
* @param factoryId
|
|
|
*/
|
|
|
- public void whenRecycleSend(Long userId,Long factoryId){
|
|
|
+ public void whenRecycleSend(Long userId, Long factoryId) {
|
|
|
//回收卡片,将海康设备上的这个用户vo.getUserId()的,这张卡片vo.getFactoryId()信息删除,下发时如果账号已过期,则删除账号信息,没有就删除账户的卡信息
|
|
|
RemoteUserAccountVo accountVo = remoteUserAccountService.getById(userId);
|
|
|
if (ObjectUtil.isEmpty(accountVo)) {
|
|
|
@@ -1061,14 +1071,14 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
accountVo.setFactoryId(factoryId);
|
|
|
Date lifespan = accountVo.getLifespan();
|
|
|
boolean deleteUser = false;
|
|
|
- if(lifespan!=null){
|
|
|
- if(lifespan.getTime()<System.currentTimeMillis()){
|
|
|
+ if (lifespan != null) {
|
|
|
+ if (lifespan.getTime() < System.currentTimeMillis()) {
|
|
|
deleteUser = true;
|
|
|
}
|
|
|
}
|
|
|
- if(!deleteUser && factoryId == null){
|
|
|
+ if (!deleteUser && factoryId == null) {
|
|
|
// 没有卡号,不用在下发了
|
|
|
- log.warn("消费机交易记录事件,无卡号,不进行下发,userId {}",userId);
|
|
|
+ log.warn("消费机交易记录事件,无卡号,不进行下发,userId {}", userId);
|
|
|
return;
|
|
|
}
|
|
|
// 实时下发数据不下发人脸,避免引起卡机
|
|
|
@@ -1078,14 +1088,14 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
}
|
|
|
|
|
|
//当新增账户、取卡、补卡、解挂时下发账户信息到所有设备上
|
|
|
- public void whenOtherOperationSend(Long userId){
|
|
|
+ public void whenOtherOperationSend(Long userId) {
|
|
|
RemoteUserAccountVo accountVo = remoteUserAccountService.getUserAccountVoBy(userId);
|
|
|
if (ObjectUtil.isEmpty(accountVo)) {
|
|
|
R.warn(MessageFormat.format("没有要处理的人员信息,userId:{0}", userId));
|
|
|
return;
|
|
|
}
|
|
|
//保持只有一张卡 deleteAllCard为true,deleteCard为false
|
|
|
- EmpInfoDto empDto = getEmpInfoDto(accountVo, false, false, false, true, false,false);
|
|
|
+ EmpInfoDto empDto = getEmpInfoDto(accountVo, false, false, false, true, false, false);
|
|
|
|
|
|
sendEmpToAllDevice(empDto);
|
|
|
}
|
|
|
@@ -1108,19 +1118,19 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
return R.ok(StringUtils.format("[IP:{}的设备查询成功],结果:{}", device.getDeviceIp(), doResult.getMsg()));
|
|
|
}
|
|
|
|
|
|
- public void currentDownSendUserCardInfo(Long userId,String operationType,Long factoryId){
|
|
|
+ public void currentDownSendUserCardInfo(Long userId, String operationType, Long factoryId) {
|
|
|
if (userId == null) {
|
|
|
log.error("userId不能为null");
|
|
|
return;
|
|
|
}
|
|
|
- switch (operationType){
|
|
|
- case BusinessOperationConstants.ADD_ACCOUNT,BusinessOperationConstants.GET_CARD,
|
|
|
- BusinessOperationConstants.AGAIN_GET_CARD,BusinessOperationConstants.UNLOCK_CARD -> // 查询用户然后下发即可
|
|
|
+ switch (operationType) {
|
|
|
+ case BusinessOperationConstants.ADD_ACCOUNT, BusinessOperationConstants.GET_CARD,
|
|
|
+ BusinessOperationConstants.AGAIN_GET_CARD, BusinessOperationConstants.UNLOCK_CARD -> // 查询用户然后下发即可
|
|
|
whenOtherOperationSend(userId);
|
|
|
case BusinessOperationConstants.DELETE_ACCOUNT -> // 删除账户
|
|
|
whenDeleteSend(userId);
|
|
|
case BusinessOperationConstants.RECYCLE_CARD -> // 回收卡片
|
|
|
- whenRecycleSend(userId,factoryId);
|
|
|
+ whenRecycleSend(userId, factoryId);
|
|
|
case BusinessOperationConstants.LOCK_CARD -> // 挂失
|
|
|
whenLockCardSend(userId);
|
|
|
default -> log.info("未知操作");
|
|
|
@@ -1135,15 +1145,15 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
@Override
|
|
|
public void increaseSend(Long termNo) {
|
|
|
XfTermVo byTermNo = xfTermService.getByTermNo(termNo);
|
|
|
- if(byTermNo == null){
|
|
|
- throw new ServiceException("设备不存在"+termNo);
|
|
|
+ if (byTermNo == null) {
|
|
|
+ throw new ServiceException("设备不存在" + termNo);
|
|
|
}
|
|
|
String ipAddress = byTermNo.getTermIp();
|
|
|
String termMac = byTermNo.getTermMac();
|
|
|
Long cacheObject = RedisUtils.getCacheObject(CacheNames.XF_TERM_IP + ipAddress);
|
|
|
- if(cacheObject == null){
|
|
|
+ if (cacheObject == null) {
|
|
|
// 第一次上线,下发最近一天的
|
|
|
- throw new ServiceException("设备从未上传过心跳,请等上传过心跳后执行:"+termNo);
|
|
|
+ throw new ServiceException("设备从未上传过心跳,请等上传过心跳后执行:" + termNo);
|
|
|
}
|
|
|
Date last = new Date(cacheObject);
|
|
|
upLoadEmpToDevice(termMac, last, true);
|
|
|
@@ -1152,17 +1162,18 @@ public class SendDeviceServiceImpl implements ISendDeviceService {
|
|
|
|
|
|
/**
|
|
|
* 获取在线设备列表
|
|
|
+ *
|
|
|
* @return 列表
|
|
|
*/
|
|
|
- public List<Long> getOnlineDeviceList(){
|
|
|
+ public List<Long> getOnlineDeviceList() {
|
|
|
List<Long> rs = new ArrayList<>();
|
|
|
Map<String, Object> cacheMap = RedisUtils.getCacheMap(CacheNames.LAST_TIME_HEARTBEAT_LIST);
|
|
|
|
|
|
- cacheMap.forEach((k,v)->{
|
|
|
- if (v instanceof Long t){
|
|
|
+ cacheMap.forEach((k, v) -> {
|
|
|
+ if (v instanceof Long t) {
|
|
|
long l = System.currentTimeMillis() - t;
|
|
|
// 正常在线的心跳时间间隔是30秒,但怕有网络延迟,这里设置60秒内都算在线
|
|
|
- if ( l <= 60 * 1000 ){
|
|
|
+ if (l <= 60 * 1000) {
|
|
|
rs.add(Long.valueOf(k));
|
|
|
}
|
|
|
}
|