Commit 72fcb711 authored by suhuiguang's avatar suhuiguang

feat(重要提醒):业务新增提醒开发联调

1.使用登记作废
parent f717b20e
package com.yeejoin.amos.boot.module.jg.biz.event.listener; package com.yeejoin.amos.boot.module.jg.biz.event.listener;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Sets;
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.jg.api.enums.BusinessTypeEnum; import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum;
import com.yeejoin.amos.boot.module.jg.biz.event.CancellationEvent; import com.yeejoin.amos.boot.module.jg.biz.event.CancellationEvent;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher; import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.EquipCreateOrEditEvent; import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.EquipCreateOrEditEvent;
import com.yeejoin.amos.boot.module.jg.biz.service.ICommonService;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgRegisterInfoServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgUseInfoServiceImpl;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgRegisterInfo;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgUseInfo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -21,7 +13,6 @@ import org.springframework.stereotype.Component; ...@@ -21,7 +13,6 @@ import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
...@@ -38,18 +29,12 @@ public class CancellationEventListener { ...@@ -38,18 +29,12 @@ public class CancellationEventListener {
@Value("${cancellation.deal.thread.number:1}") @Value("${cancellation.deal.thread.number:1}")
private int threadNumber; private int threadNumber;
private final ICommonService commonService; private final BlockingQueue<String> queue = new LinkedBlockingQueue<>();
private final ESEquipmentCategory esEquipmentCategoryDao;
private final IdxBizJgUseInfoServiceImpl idxBizJgUseInfoService;
private final IdxBizJgRegisterInfoServiceImpl idxBizJgRegisterInfoService;
private BlockingQueue<String> queue = new LinkedBlockingQueue<>();
private final EventPublisher publisher; private final EventPublisher publisher;
private final ManageStatusDataUpdateService updateService;
@EventListener(value = CancellationEvent.class) @EventListener(value = CancellationEvent.class)
public void handleTransactionalEvent(CancellationEvent event) { public void handleTransactionalEvent(CancellationEvent event) {
List<String> records = event.getRecords(); List<String> records = event.getRecords();
...@@ -64,10 +49,6 @@ public class CancellationEventListener { ...@@ -64,10 +49,6 @@ public class CancellationEventListener {
} }
} }
private void castEvent2EquipEditEvent(String record) {
publisher.publish(new EquipCreateOrEditEvent(this, BusinessTypeEnum.JG_NEW_EQUIP.name(), Sets.newHashSet(record), EquipCreateOrEditEvent.EquipType.equip));
}
@PostConstruct @PostConstruct
public void init() { public void init() {
ExecutorService executorService = Executors.newFixedThreadPool(threadNumber, r -> { ExecutorService executorService = Executors.newFixedThreadPool(threadNumber, r -> {
...@@ -81,7 +62,7 @@ public class CancellationEventListener { ...@@ -81,7 +62,7 @@ public class CancellationEventListener {
try { try {
String record = queue.take(); String record = queue.take();
log.info("线程 {} 开始处理 record: {}", Thread.currentThread().getName(), record); log.info("线程 {} 开始处理 record: {}", Thread.currentThread().getName(), record);
this.dealData(record); updateService.dealData(record);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
...@@ -91,40 +72,5 @@ public class CancellationEventListener { ...@@ -91,40 +72,5 @@ public class CancellationEventListener {
} }
} }
private void dealData(String record) {
log.info("开始检查设备的引用:{}", record);
// 所有业务单据(除去作废、删除状态单据),有在引用设备的则不修改设备纳管状态
Boolean inUsed = commonService.checkEquipIsUsed(record);
// 无引用则进行修改纳管状态为未纳管
if (!inUsed) {
log.info("进行设备作废处理:{}", record);
try {
// 更新已纳管为未纳管 - 数据库
idxBizJgUseInfoService.lambdaUpdate()
.eq(IdxBizJgUseInfo::getRecord, record)
.set(IdxBizJgUseInfo::getIsIntoManagement, false)
.update();
// 清除系统自动生成的设备代码`equCode`
boolean isRegisterUpdated = idxBizJgRegisterInfoService.lambdaUpdate()
.eq(IdxBizJgRegisterInfo::getRecord, record)
.eq(IdxBizJgRegisterInfo::getEquCodeType, "2")
.set(IdxBizJgRegisterInfo::getEquCode, null)
.update();
// 同步修改ES数据
Optional<ESEquipmentCategoryDto> optional = esEquipmentCategoryDao.findById(record);
optional.ifPresent(esEquipmentCategoryDto -> {
esEquipmentCategoryDto.setIS_INTO_MANAGEMENT(false);
if (isRegisterUpdated) {
esEquipmentCategoryDto.setEQU_CODE(null);
}
esEquipmentCategoryDao.save(esEquipmentCategoryDto);
});
castEvent2EquipEditEvent(record);
} catch (Exception e) {
log.error("设备作废异常:{}", e.getMessage());
}
}
}
} }
package com.yeejoin.amos.boot.module.jg.biz.event.listener;
import com.google.common.collect.Sets;
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.jg.api.enums.BusinessTypeEnum;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.EquipCreateOrEditEvent;
import com.yeejoin.amos.boot.module.jg.biz.service.ICommonService;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgRegisterInfoServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgUseInfoServiceImpl;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgRegisterInfo;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgUseInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
@Service
@Slf4j
@RequiredArgsConstructor
public class ManageStatusDataUpdateService {
private final EventPublisher publisher;
private final ICommonService commonService;
private final ESEquipmentCategory esEquipmentCategoryDao;
private final IdxBizJgUseInfoServiceImpl idxBizJgUseInfoService;
private final IdxBizJgRegisterInfoServiceImpl idxBizJgRegisterInfoService;
@Transactional(rollbackFor = Exception.class)
public void dealData(String record) {
log.info("开始检查设备的引用:{}", record);
// 所有业务单据(除去作废、删除状态单据),有在引用设备的则不修改设备纳管状态
Boolean inUsed = commonService.checkEquipIsUsed(record);
// 无引用则进行修改纳管状态为未纳管
if (!inUsed) {
log.info("进行设备作废处理:{}", record);
try {
// 更新已纳管为未纳管 - 数据库
idxBizJgUseInfoService.lambdaUpdate()
.eq(IdxBizJgUseInfo::getRecord, record)
.set(IdxBizJgUseInfo::getIsIntoManagement, false)
.update();
// 清除系统自动生成的设备代码`equCode`
boolean isRegisterUpdated = idxBizJgRegisterInfoService.lambdaUpdate()
.eq(IdxBizJgRegisterInfo::getRecord, record)
.eq(IdxBizJgRegisterInfo::getEquCodeType, "2")
.set(IdxBizJgRegisterInfo::getEquCode, null)
.update();
// 同步修改ES数据
Optional<ESEquipmentCategoryDto> optional = esEquipmentCategoryDao.findById(record);
optional.ifPresent(esEquipmentCategoryDto -> {
esEquipmentCategoryDto.setIS_INTO_MANAGEMENT(false);
if (isRegisterUpdated) {
esEquipmentCategoryDto.setEQU_CODE(null);
}
esEquipmentCategoryDao.save(esEquipmentCategoryDto);
});
castEvent2EquipEditEvent(record);
} catch (Exception e) {
log.error("设备作废异常:{}", e.getMessage());
}
}
}
private void castEvent2EquipEditEvent(String record) {
publisher.publish(new EquipCreateOrEditEvent(this, BusinessTypeEnum.JG_NEW_EQUIP.name(), Sets.newHashSet(record), EquipCreateOrEditEvent.EquipType.equip));
}
}
package com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.listener; package com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.listener;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.EquipCreateOrEditEvent;
import com.yeejoin.amos.boot.module.jg.biz.reminder.biz.factory.QualityScoreUpdateFactory; import com.yeejoin.amos.boot.module.jg.biz.reminder.biz.factory.QualityScoreUpdateFactory;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.event.EquipCreateOrEditEvent;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
......
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