Commit f610bc2e authored by suhuiguang's avatar suhuiguang

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

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