Commit f610bc2e authored by suhuiguang's avatar suhuiguang

feat(jg): 压力管道后续业务

1.自测bug修改
parent 5228be65
package com.yeejoin.amos.boot.module.jg.biz.context;
import com.yeejoin.amos.boot.module.jg.biz.edit.process.biz.strategy.IBizDataChangeHandleStrategy;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author Administrator
*/
@Component
public class BizDataHandleStrategyContext implements ApplicationContextAware {
public class BizDataHandleStrategyContext {
private static final Map<String, IBizDataChangeHandleStrategy> dataProcessStrategyHashMap = new HashMap<>();
private final Map<String, IBizDataChangeHandleStrategy> strategyMap;
public static IBizDataChangeHandleStrategy getStrategy(String bizType) {
return Optional.ofNullable(dataProcessStrategyHashMap.get(bizType)).orElseThrow(() -> new RuntimeException(String.format("not found %s type strategy", bizType)));
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, IBizDataChangeHandleStrategy> strategyBeans = applicationContext.getBeansOfType(IBizDataChangeHandleStrategy.class);
if (strategyBeans.isEmpty()) {
return;
}
for (IBizDataChangeHandleStrategy strategy : strategyBeans.values()) {
dataProcessStrategyHashMap.put(strategy.canHandleBizType(), strategy);
public BizDataHandleStrategyContext(List<IBizDataChangeHandleStrategy> strategies) {
this.strategyMap = strategies.stream()
.collect(Collectors.toMap(
IBizDataChangeHandleStrategy::canHandleBizType,
Function.identity()
));
}
public IBizDataChangeHandleStrategy getStrategy(String bizType) {
return Optional.ofNullable(strategyMap.get(bizType)).orElseThrow(() -> new RuntimeException(String.format("not found %s type strategy", bizType)));
}
}
......@@ -11,14 +11,18 @@ import com.yeejoin.amos.boot.module.jg.biz.controller.BizDataChangeController;
import com.yeejoin.amos.boot.module.jg.biz.edit.permission.FillingCompanyTypeForCurrentUser;
import com.yeejoin.amos.boot.module.jg.biz.edit.process.biz.strategy.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.CommonServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
@Service
@RequiredArgsConstructor
public class BizDataChangeServiceImpl {
private final BizDataHandleStrategyContext handleStrategyContext;
/**
* 变更保存
......@@ -34,12 +38,12 @@ public class BizDataChangeServiceImpl {
String applyNo,
String bizType,
IBizDataChangeHandleStrategy.ModelType modelType, RequestChangeData changeData, ReginParams selectedOrgInfo) {
IBizDataChangeHandleStrategy handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType);
IBizDataChangeHandleStrategy handleStrategy = handleStrategyContext.getStrategy(bizType);
handleStrategy.doSave(bizId, applyNo, modelType, changeData, selectedOrgInfo);
}
public IPage<?> queryDetail(String applyNo, String bizType, BizDataChangeController.DetailType type, JSONObject searchParams) {
IBizDataChangeHandleStrategy handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType);
IBizDataChangeHandleStrategy handleStrategy = handleStrategyContext.getStrategy(bizType);
return handleStrategy.getDetail(applyNo, type, searchParams);
}
......@@ -52,7 +56,7 @@ public class BizDataChangeServiceImpl {
)
})
public Map<String, Object> querySubDetail(String applyNo, String bizId, String bizType, BizDataChangeController.DetailType type, ReginParams selectedOrgInfo) {
IBizDataChangeHandleStrategy handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType);
IBizDataChangeHandleStrategy handleStrategy = handleStrategyContext.getStrategy(bizType);
// 装饰器模式增强结果
return new FillingCompanyTypeForCurrentUser(new JSONObject(handleStrategy.getSubDetail(applyNo, bizId, type)), selectedOrgInfo.getCompany()).getData();
}
......@@ -61,7 +65,7 @@ public class BizDataChangeServiceImpl {
if (bizId == null || bizId.isEmpty()) {
return new Page<>(current, size);
}
IBizDataChangeHandleStrategy handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType);
IBizDataChangeHandleStrategy handleStrategy = handleStrategyContext.getStrategy(bizType);
return handleStrategy.getChangeLogs(bizId, current, size);
}
}
......@@ -19,7 +19,6 @@ import com.yeejoin.amos.boot.module.jg.biz.edit.process.equip.strategy.IEquipCha
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgBizChangeLogServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
......@@ -33,6 +32,10 @@ public abstract class DefaultBizDataChangeHandler<U extends BaseBizDataChangeEve
public static String TEMPORARY_PIPELINES_DATA = "temporaryPipelinesData";
public static String CHANGE_REASON = "changeReason";
public static String CHANGE_ATTACHMENT = "changeAttachment";
private final CommonPublisher eventPublisher;
private final ApplicationContext applicationContext;
......@@ -45,27 +48,62 @@ public abstract class DefaultBizDataChangeHandler<U extends BaseBizDataChangeEve
@Override
public final void doSave(String bizId, String applyNo, ModelType model, Map<String, Object> changeData, ReginParams selectedOrgInfo) {
if (beforeCheck(bizId, applyNo, model, changeData)) {
// 前置检查
if (!beforeCheck(bizId, applyNo, model, changeData)) {
return;
}
// 预处理
preSave(bizId, applyNo, model, changeData);
JSONObject oData = new JSONObject();
BeanUtil.copyProperties(changeData, oData);
// 删除原始提交的变更说明及附件放置后续存放到json
changeData.remove("changeReason");
changeData.remove("changeAttachment");
JSONObject originalData = prepareOriginalData(changeData, applyNo);
// 核心处理
HandleResult handleResult = processDataChanges(bizId, model, changeData);
// 后处理
List<FieldChangeMeta> postColumnChanges = postSave(bizId, applyNo, model, changeData, Optional.ofNullable(handleResult.getFieldChangeMetas()).orElseGet(ArrayList::new), handleResult.getPipelineChangeItemMap());
// 合并变更信息
List<FieldChangeMeta> allChangeColumns = combineChanges(handleResult, postColumnChanges);
// 发送数据变更消息
publish2OtherBiz(allChangeColumns, applyNo, originalData, selectedOrgInfo);
}
private JSONObject prepareOriginalData(Map<String, Object> changeData, String applyNo) {
JSONObject originalData = new JSONObject();
BeanUtil.copyProperties(changeData, originalData);
// 移除临时字段
changeData.remove(CHANGE_REASON);
changeData.remove(CHANGE_ATTACHMENT);
// 添加处理标记
changeData.put(IS_REQUIRES_TEMPORARY_SAVE, requiresTemporarySave(applyNo));
changeData.put(TEMPORARY_PIPELINES_DATA, getsTemporaryData(applyNo));
IEquipChangeDataProcessStrategy dataProcessor = EquipDataProcessStrategyContext.getStrategy(model);
HandleResult handleResult = dataProcessor.handle(changeData, bizId);
List<FieldChangeMeta> allChangeColumns = handleResult.getFieldChangeMetas() == null ? new ArrayList<>() : handleResult.getFieldChangeMetas();
List<FieldChangeMeta> bizEditColumns = postSave(bizId, applyNo, model, changeData, allChangeColumns, handleResult.getPipelineChangeItemMap());
allChangeColumns.addAll(bizEditColumns);
// 发送数据变更消息
publish2OtherBiz(allChangeColumns, applyNo, oData, selectedOrgInfo);
return originalData;
}
private HandleResult processDataChanges(String bizId,
ModelType model,
Map<String, Object> changeData) {
IEquipChangeDataProcessStrategy processor = EquipDataProcessStrategyContext.getStrategy(model);
return processor.handle(changeData, bizId);
}
private List<FieldChangeMeta> combineChanges(HandleResult handleResult,
List<FieldChangeMeta> bizChanges) {
List<FieldChangeMeta> allChanges = Optional.ofNullable(handleResult.getFieldChangeMetas()).orElseGet(ArrayList::new);
allChanges.addAll(bizChanges);
return allChanges;
}
/**
* 管道专用-是否需要暂存数据-暂存保存数据到json
*
* @param applyNo 单据号
* @return true-存json;false-实时存库
*/
......@@ -92,8 +130,8 @@ public abstract class DefaultBizDataChangeHandler<U extends BaseBizDataChangeEve
bizRelationDataDto.setBizId(applyNo);
bizRelationDataDto.setBizType(canHandleBizType());
bizRelationDataDto.setRecords(getEqs(applyNo));
bizRelationDataDto.setChangeReason(oData.getString("changeReason"));
bizRelationDataDto.setChangeAttachment(oData.get("changeAttachment") != null ? JSONObject.toJSONString(oData.get("changeAttachment")) : null);
bizRelationDataDto.setChangeReason(oData.getString(CHANGE_REASON));
bizRelationDataDto.setChangeAttachment(oData.get(CHANGE_ATTACHMENT) != null ? JSONObject.toJSONString(oData.get(CHANGE_ATTACHMENT)) : null);
bizRelationDataDto.setProjectContraptionIds(getProjectContraptionIds(applyNo));
bizRelationDataDto.setRecUserName(selectedOrgInfo.getUserModel().getRealName());
bizRelationDataDto.setUnitCode(selectedOrgInfo.getCompany().getCompanyCode());
......@@ -140,4 +178,5 @@ public abstract class DefaultBizDataChangeHandler<U extends BaseBizDataChangeEve
JgBizChangeLogServiceImpl service = applicationContext.getBean(JgBizChangeLogServiceImpl.class);
return service.queryPageListByChangeIds(changeIds, current, size);
}
}
......@@ -908,6 +908,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
equipments.add(item);
});
} else {
buildNewProjectBaseInfo(enableDisable, resultMap);
equipments = this.getBaseMapper().selectPipeLineByRecords(enableDisableEqs.stream().map(JgEnableDisableEq::getEquId).collect(Collectors.toList()));
// 检验报告数据格式化 转json
equipments.stream().filter(e -> e.get("inspectReport") != null).forEach(item -> {
......@@ -930,6 +931,15 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
return resultMap;
}
private void buildNewProjectBaseInfo(JgEnableDisable enableDisable, Map<String, Object> resultMap) {
IdxBizJgProjectContraptionDto idxBizJgProjectContraptionDto = findOneProjectContraption(enableDisable.getProjectContraptionId());
resultMap.put("projectContraption", idxBizJgProjectContraptionDto.getProjectContraption());
resultMap.put("projectContraptionNo", idxBizJgProjectContraptionDto.getProjectContraptionNo());
resultMap.put("productPhoto", idxBizJgProjectContraptionDto.getProductPhoto());
resultMap.put("proOtherAccessories", idxBizJgProjectContraptionDto.getProOtherAccessories());
resultMap.put("productQualificationCertificate", idxBizJgProjectContraptionDto.getProductQualificationCertificate());
}
private String concatWithSplit(String... strs) {
return Arrays.stream(strs).filter(org.apache.commons.lang3.StringUtils::isNotEmpty).collect(Collectors.joining("/"));
}
......@@ -1015,6 +1025,10 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
}
public IdxBizJgProjectContraptionDto findOneProjectContraption(Long sequenceNbr) {
return findOneProjectContraption(String.valueOf(sequenceNbr));
}
private IdxBizJgProjectContraptionDto findOneProjectContraption(String sequenceNbr) {
IdxBizJgProjectContraption bizJgProjectContraption = jgProjectContraptionMapper.selectById(sequenceNbr);
IdxBizJgProjectContraptionDto dto = new IdxBizJgProjectContraptionDto();
BeanUtil.copyProperties(bizJgProjectContraption, dto);
......
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