Commit a51e8f0d authored by suhuiguang's avatar suhuiguang

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

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