Commit bc21d1b2 authored by suhuiguang's avatar suhuiguang

feat(综合搜索):增量数据同步调整

1.大编辑时,会触发重要提醒时的评分计算,在评分计算时,进行约束,只有目前实现的评分才会进行评分,否则设备等级会变为3级
parent 0bf213ef
......@@ -27,5 +27,9 @@ public class Constants {
public static final Integer REFRESH_STATUS_FAILURE = 3;
public static final String JG_EDIT_PROJECT = "JG_EDIT_PROJECT";
public static final String JG_EDIT_EQUIP = "JG_EDIT_EQUIP";
}
......@@ -3,11 +3,14 @@ package com.yeejoin.amos.boot.module.jg.biz.reminder.biz.factory;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.EquipCreateOrEditEvent;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.IQualityScoreUpdate;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@Component
......@@ -18,7 +21,7 @@ public class QualityScoreUpdateFactory {
private final Map<String, IQualityScoreUpdate> qualityScoreUpdaterMap = new ConcurrentHashMap<>();
public IQualityScoreUpdate getUpdater(EquipCreateOrEditEvent.EquipType equipType) {
private IQualityScoreUpdate getUpdater(EquipCreateOrEditEvent.EquipType equipType) {
return qualityScoreUpdaterMap.computeIfAbsent(equipType.name(), (k) -> {
for (IQualityScoreUpdate qualityScoreUpdater : qualityScoreUpdaters) {
if (qualityScoreUpdater.support(equipType)) {
......@@ -28,4 +31,12 @@ public class QualityScoreUpdateFactory {
throw new BadRequest("not found updater handler for " + equipType.name());
});
}
@Async
@Transactional(rollbackFor = Exception.class)
public void update(EquipCreateOrEditEvent.EquipType equipType, String bizType, Set<String> recordOrPIds) {
IQualityScoreUpdate qualityScoreUpdateHandler = getUpdater(equipType);
qualityScoreUpdateHandler.doUpdate(bizType, recordOrPIds);
}
}
......@@ -60,6 +60,6 @@ public class EquipOperationEventHandler {
private void processEvent(EquipCreateOrEditEvent event) {
qualityScoreUpdateFactory.getUpdater(event.getEquipType()).update(event.getBizType(), event.getUpdatedIds());
qualityScoreUpdateFactory.update(event.getEquipType(), event.getBizType(), event.getUpdatedIds());
}
}
package com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service;
import java.util.Set;
public abstract class DefaultQualityScoreUpdateService implements IQualityScoreUpdate {
/**
* 前置处理-定义目前支持的业务类型,由于目前仅实现使用登记、新增设备、新增装置、大编辑设备、大编辑装置、安装告知准则,
* 所有都实现后返回true即可
* @param bizType 业务类型
* @return 是否通过前置检验
*/
protected abstract Boolean preHandle(String bizType);
public void doUpdate(String bizType, Set<String> recordOrPIds) {
if (preHandle(bizType)) {
doHandle(bizType, recordOrPIds);
}
afterHandle(recordOrPIds);
}
/**
* 执行
* @param bizType 业务类型
* @param recordOrPIds 装置或者设备id集合
*/
protected abstract void doHandle(String bizType, Set<String> recordOrPIds);
/**
* 事后处理
* @param recordOrPIds 装置或者设备id集合
*/
protected abstract void afterHandle(Set<String> recordOrPIds);
}
......@@ -7,5 +7,5 @@ import java.util.Set;
public interface IQualityScoreUpdate {
Boolean support(EquipCreateOrEditEvent.EquipType equipType);
void update(String bizType, Set<String> bizIds);
void doUpdate(String bizType, Set<String> recordOrPIds);
}
......@@ -5,13 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yeejoin.amos.boot.biz.common.entity.TzsBaseEntity;
import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.common.biz.constats.Constants;
import com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent;
import com.yeejoin.amos.boot.module.common.biz.service.impl.EquipmentCategoryService;
import com.yeejoin.amos.boot.module.jg.api.dto.ReminderItemDto;
import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import com.yeejoin.amos.boot.module.jg.biz.reminder.biz.factory.GradeStrategyFactory;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.EquipCreateOrEditEvent;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.IQualityScoreUpdate;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.DefaultQualityScoreUpdateService;
import com.yeejoin.amos.boot.module.jg.biz.reminder.dto.MatchItemDto;
import com.yeejoin.amos.boot.module.jg.biz.reminder.service.CommonReminderService;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgRegisterInfoServiceImpl;
......@@ -21,17 +23,14 @@ import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgUseInfo;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentClassifityEnum;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@Component
@RequiredArgsConstructor
public class EquipQualityScoreUpdateService implements IQualityScoreUpdate {
public class EquipQualityScoreUpdateService extends DefaultQualityScoreUpdateService {
private final ESEquipmentCategory equipmentCategoryDao;
......@@ -55,32 +54,8 @@ public class EquipQualityScoreUpdateService implements IQualityScoreUpdate {
return EquipCreateOrEditEvent.EquipType.equip.equals(equipType);
}
@Async
@Override
@Transactional(rollbackFor = Exception.class)
public void update(String bizType, Set<String> records) {
records.forEach(record -> {
Optional<ESEquipmentCategoryDto> op = equipmentCategoryDao.findById(record);
// 压力管道不进行管道登记的计算
if (op.isPresent() && op.get().getEQU_LIST_CODE().equals(EquipmentClassifityEnum.YLGD.getCode())) {
return;
}
Integer level = this.getReminderLevel(bizType, record);
op.ifPresent(equipmentCategory -> {
equipmentCategory.setDataQualityScore(level);
equipmentCategoryService.saveWithImmediateRefresh(equipmentCategory);
});
LambdaUpdateWrapper<IdxBizJgUseInfo> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(IdxBizJgUseInfo::getRecord, record);
updateWrapper.set(IdxBizJgUseInfo::getDataQualityScore, level);
updateWrapper.set(TzsBaseEntity::getRecDate, new Date());
idxBizJgUseInfoService.update(updateWrapper);
});
// 事务提交后发送数据变更消息
this.sendDataRefreshMsgEquip(new ArrayList<>(records));
}
public Integer getReminderLevel(String bizType, String record) {
private Integer getReminderLevel(String bizType, String record) {
MatchItemDto matchItemDto = MatchItemDto.builder().build();
IdxBizJgUseInfo useInfo = getIdxBizJgUseInfo(record);
IdxBizJgRegisterInfo registerInfo = getIdxBizJgRegisterInfo(record);
......@@ -119,4 +94,40 @@ public class EquipQualityScoreUpdateService implements IQualityScoreUpdate {
private void sendDataRefreshMsgEquip(List<String> records) {
eventPublisher.publish(new DataRefreshEvent(this, records, DataRefreshEvent.DataType.equipment.name(), DataRefreshEvent.Operation.UPDATE));
}
@Override
protected Boolean preHandle(String bizType) {
return BusinessTypeEnum.JG_USAGE_REGISTRATION.name().equals(bizType) ||
BusinessTypeEnum.JG_INSTALLATION_NOTIFICATION.name().equals(bizType) ||
BusinessTypeEnum.JG_NEW_EQUIP.name().equals(bizType) ||
BusinessTypeEnum.JG_VEHICLE_GAS_APPLICATION.name().equals(bizType) ||
Constants.JG_EDIT_EQUIP.equals(bizType);
}
@Override
protected void doHandle(String bizType, Set<String> recordOrPIds) {
recordOrPIds.forEach(record -> {
Optional<ESEquipmentCategoryDto> op = equipmentCategoryDao.findById(record);
// 压力管道不进行管道登记的计算
if (op.isPresent() && op.get().getEQU_LIST_CODE().equals(EquipmentClassifityEnum.YLGD.getCode())) {
return;
}
Integer level = this.getReminderLevel(bizType, record);
op.ifPresent(equipmentCategory -> {
equipmentCategory.setDataQualityScore(level);
equipmentCategoryService.saveWithImmediateRefresh(equipmentCategory);
});
LambdaUpdateWrapper<IdxBizJgUseInfo> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(IdxBizJgUseInfo::getRecord, record);
updateWrapper.set(IdxBizJgUseInfo::getDataQualityScore, level);
updateWrapper.set(TzsBaseEntity::getRecDate, new Date());
idxBizJgUseInfoService.update(updateWrapper);
});
}
@Override
protected void afterHandle(Set<String> recordOrPIds) {
// 事务提交后发送数据变更消息
this.sendDataRefreshMsgEquip(new ArrayList<>(recordOrPIds));
}
}
......@@ -4,12 +4,14 @@ import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.common.biz.constats.Constants;
import com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent;
import com.yeejoin.amos.boot.module.jg.api.dto.ReminderItemDto;
import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import com.yeejoin.amos.boot.module.jg.biz.reminder.biz.factory.GradeStrategyFactory;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.EquipCreateOrEditEvent;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.IQualityScoreUpdate;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.service.DefaultQualityScoreUpdateService;
import com.yeejoin.amos.boot.module.jg.biz.reminder.dto.MatchItemDto;
import com.yeejoin.amos.boot.module.jg.biz.reminder.service.CommonReminderService;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgUseInfoService;
......@@ -19,9 +21,7 @@ import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgUseInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.Date;
......@@ -31,7 +31,7 @@ import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
public class ProjectQualityScoreUpdateService implements IQualityScoreUpdate {
public class ProjectQualityScoreUpdateService extends DefaultQualityScoreUpdateService {
private final GradeStrategyFactory gradeStrategyFactory;
......@@ -50,23 +50,7 @@ public class ProjectQualityScoreUpdateService implements IQualityScoreUpdate {
return EquipCreateOrEditEvent.EquipType.project.equals(equipType);
}
@Async
@Override
@Transactional(rollbackFor = Exception.class)
public void update(String bizType, Set<String> projectContraptionIds) {
projectContraptionIds.forEach(projectContraptionId -> {
Integer level = this.getReminderLevel(bizType, projectContraptionId);
LambdaUpdateWrapper<IdxBizJgProjectContraption> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(IdxBizJgProjectContraption::getSequenceNbr, projectContraptionId);
updateWrapper.set(IdxBizJgProjectContraption::getDataQualityScore, level);
updateWrapper.set(BaseEntity::getRecDate, new Date());
idxBizJgProjectContraptionService.update(updateWrapper);
});
this.sendDataRefreshMsg(projectContraptionIds);
}
public Integer getReminderLevel(String bizType, String projectContraptionId) {
private Integer getReminderLevel(String bizType, String projectContraptionId) {
IdxBizJgProjectContraption projectContraption = idxBizJgProjectContraptionService.getById(projectContraptionId);
MatchItemDto matchItemDto = MatchItemDto.builder().build();
matchItemDto.setBizType(bizType);
......@@ -94,4 +78,29 @@ public class ProjectQualityScoreUpdateService implements IQualityScoreUpdate {
.select(IdxBizJgUseInfo::getRecord));
eventPublisher.publish(new DataRefreshEvent(this, useInfos.stream().map(IdxBizJgUseInfo::getRecord).collect(Collectors.toList()), DataRefreshEvent.DataType.equipment.name(), DataRefreshEvent.Operation.UPDATE));
}
@Override
protected Boolean preHandle(String bizType) {
return BusinessTypeEnum.JG_USAGE_REGISTRATION.name().equals(bizType) ||
BusinessTypeEnum.JG_INSTALLATION_NOTIFICATION.name().equals(bizType) ||
BusinessTypeEnum.JG_NEW_PROJECT.name().equals(bizType) ||
Constants.JG_EDIT_PROJECT.equals(bizType);
}
@Override
protected void doHandle(String bizType, Set<String> projectContraptionIds) {
projectContraptionIds.forEach(projectContraptionId -> {
Integer level = this.getReminderLevel(bizType, projectContraptionId);
LambdaUpdateWrapper<IdxBizJgProjectContraption> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(IdxBizJgProjectContraption::getSequenceNbr, projectContraptionId);
updateWrapper.set(IdxBizJgProjectContraption::getDataQualityScore, level);
updateWrapper.set(BaseEntity::getRecDate, new Date());
idxBizJgProjectContraptionService.update(updateWrapper);
});
}
@Override
protected void afterHandle(Set<String> projectContraptionIds) {
this.sendDataRefreshMsg(projectContraptionIds);
}
}
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