Commit a51e8f0d authored by suhuiguang's avatar suhuiguang

feat(综合搜索):增量更新

1.、数据同步增加删除逻辑
parent 09c5b193
package com.yeejoin.amos.boot.module.common.biz.refresh.dispatch;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.common.api.entity.TzsDataRefreshMessage;
import com.yeejoin.amos.boot.module.common.api.service.IDataRefreshDispatch;
import com.yeejoin.amos.boot.module.common.api.service.IDataRefreshHandler;
import com.yeejoin.amos.boot.module.common.biz.constats.Constants;
import com.yeejoin.amos.boot.module.common.biz.refresh.factory.RefreshHandlerFactory;
import com.yeejoin.amos.boot.module.common.biz.service.impl.TzsDataRefreshMessageServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
......@@ -13,21 +16,36 @@ import java.util.Date;
@Component
@RequiredArgsConstructor
public class RefreshDispatch implements IDataRefreshDispatch {
@Slf4j
public class DataRefreshDispatcher implements IDataRefreshDispatch {
private final RefreshHandlerFactory handlerFactory;
private final TzsDataRefreshMessageServiceImpl tzsDataRefreshMessageService;
private final RefreshHandlerFactory refreshHandlerFactory;
private final TzsDataRefreshMessageServiceImpl refreshMessageService;
@Override
@Async
public void doDispatch(TzsDataRefreshMessage message) {
handlerFactory.getRefreshHandler(message.getDataType()).doRefresh(message);
finishMessage(message);
public void doDispatch(TzsDataRefreshMessage refreshMessage) {
try {
IDataRefreshHandler dataRefreshHandler = refreshHandlerFactory.getRefreshHandler(refreshMessage.getDataType());
dataRefreshHandler.doRefresh(refreshMessage);
markRefreshSuccess(refreshMessage);
} catch (Exception e) {
log.error("三库数据刷新执行失败,消息内容:{}", JSONObject.toJSONString(refreshMessage), e);
markRefreshFailure(refreshMessage);
}
}
private void markRefreshSuccess(TzsDataRefreshMessage message) {
updateMessageStatus(message, Constants.REFRESH_STATUS_SUCCESS);
}
private void markRefreshFailure(TzsDataRefreshMessage message) {
updateMessageStatus(message, Constants.REFRESH_STATUS_FAILURE);
}
private void finishMessage(TzsDataRefreshMessage message) {
message.setStatus(Constants.REFRESH_STATUS_SUCCESS);
private void updateMessageStatus(TzsDataRefreshMessage message, Integer status) {
message.setStatus(status);
message.setRecDate(new Date());
tzsDataRefreshMessageService.saveOrUpdate(message);
refreshMessageService.saveOrUpdate(message);
}
}
......@@ -53,7 +53,7 @@ public class EquipRefreshHandler implements IDataRefreshHandler {
@Override
public void doRefresh(TzsDataRefreshMessage message) {
log.info("3库数据,设备开始刷库:唯一标识:{}", message.getDataId());
switch (DataRefreshEvent.Operation.valueOf(message.getOperation())){
switch (DataRefreshEvent.Operation.valueOf(message.getOperation())) {
case DELETE:
esEquipmentDao.deleteById(message.getDataId());
case INSERT:
......@@ -73,8 +73,8 @@ public class EquipRefreshHandler implements IDataRefreshHandler {
IdxBizJgInspectionDetectionInfo inspectionDetectionInfo = iIdxBizJgInspectionDetectionInfoService.queryNewestDetailByRecord(record);
IdxBizJgMaintenanceRecordInfo lastMaintenanceRecordInfo = maintenanceRecordInfoService.queryNewestDetailByRecord(record);
try {
esEquipmentInfo.setINSPECT_DATE(inspectionDetectionInfo.getSequenceNbr() != null ? inspectionDetectionInfo.getInspectDate() != null ? inspectionDetectionInfo.getInspectDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null :null);
esEquipmentInfo.setNEXT_INSPECT_DATE(inspectionDetectionInfo.getSequenceNbr() != null ? inspectionDetectionInfo.getNextInspectDate() != null ? inspectionDetectionInfo.getNextInspectDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null :null);
esEquipmentInfo.setINSPECT_DATE(inspectionDetectionInfo.getSequenceNbr() != null ? inspectionDetectionInfo.getInspectDate() != null ? inspectionDetectionInfo.getInspectDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null : null);
esEquipmentInfo.setNEXT_INSPECT_DATE(inspectionDetectionInfo.getSequenceNbr() != null ? inspectionDetectionInfo.getNextInspectDate() != null ? inspectionDetectionInfo.getNextInspectDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null : null);
esEquipmentInfo.setCreateDate(useInfo.getCreateDate() != null ? useInfo.getCreateDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime() : null);
} catch (Exception e) {
log.error("时区转换失败:{}", record, e);
......@@ -90,7 +90,7 @@ public class EquipRefreshHandler implements IDataRefreshHandler {
esEquipmentDao.save(esEquipmentInfo);
break;
default:
log.error("uno operation: {}",message.getOperation());
log.error("unknown operation: {}", message.getOperation());
}
}
......
......@@ -81,7 +81,7 @@ public class EnterpriseRefreshHandler implements IDataRefreshHandler {
}
break;
default:
log.error("uno operation: {}", message.getOperation());
log.error("unknown operation: {}", message.getOperation());
break;
}
}
......
......@@ -68,7 +68,7 @@ public class UserRefreshHandler implements IDataRefreshHandler {
esUserInfoDao.save(esUserInfo);
break;
default:
log.error("uno operation: {}", message.getOperation());
log.error("unknown operation: {}", message.getOperation());
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment