diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/helper/ProjectChangeStopHelper.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/helper/ProjectChangeStopHelper.java
index 44e95be..64c2acc 100644
--- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/helper/ProjectChangeStopHelper.java
+++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/helper/ProjectChangeStopHelper.java
@@ -21,7 +21,6 @@ import com.hz.pm.api.projectdeclared.service.IProjectChangeHistoryService;
import com.hz.pm.api.projectdeclared.service.IPurchaseService;
import com.hz.pm.api.projectdeclared.utils.BeanDiffUtil.FieldDiff;
import com.hz.pm.api.projectlib.entity.PurchaseStatusChange;
-import com.hz.pm.api.projectlib.manage.ProjectGovSystemReplaceInfoManage;
import com.hz.pm.api.projectlib.manage.ProjectLibManage;
import com.hz.pm.api.projectlib.model.dto.ProjectDTO;
import com.hz.pm.api.projectlib.model.entity.Project;
@@ -34,11 +33,11 @@ import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.util.CollUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.function.Function;
/**
*
@@ -59,7 +58,6 @@ public class ProjectChangeStopHelper {
private final IOperationService operationService;
private final IContractService contractService;
private final IProjectService projectService;
- private final ProjectGovSystemReplaceInfoManage projectGovSystemReplaceInfoManage;
private final ProjectLibManage projectLibManage;
/**
@@ -68,6 +66,7 @@ public class ProjectChangeStopHelper {
* @param project 项目
* @param event event
*/
+ @Transactional(rollbackFor = Exception.class)
public void changeProjectPurchaseStatus(Project project, ProjectStateChangeEvent event) {
TenderStateChangeEvent tenderEvent = TenderStateChangeEvent.valueOf(event.name());
ProjectStateChangeEvent beforeEvent;
@@ -219,22 +218,17 @@ public class ProjectChangeStopHelper {
List projectDiffs = projectEdit.getProjectDiffs();
if (projectDiffs != null && !projectDiffs.isEmpty()) {
ProjectDTO projectDetail = projectEdit.getProject();
- LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate(Project.class);
- projectDiffs.forEach(fieldDiff -> {
- String fieldName = fieldDiff.getFieldName();
- Object newValue = fieldDiff.getNewValue();
- Function reference = MethodReferenceUtil.getReference(Project.class, fieldName);
- if (reference != null) {
- wrapper.set((SFunction) reference, newValue);
- }
- if (ProjectDTO.SYSTEM_REPLACE_INFOS.equals(fieldName)) {
- projectLibManage.saveGovSystemReplaceInfos(projectDetail.getId(),
- projectDetail.getProjectCode(),
- projectDetail.getSystemReplaceInfos());
- }
- });
- wrapper.eq(Project::getId, projectDetail.getId());
- projectService.update(wrapper);
+ FieldDiff systemReplaceInfos = CollUtil.findOne(projectDiffs,
+ w -> w.getFieldName().equals(ProjectDTO.SYSTEM_REPLACE_INFOS));
+ if (systemReplaceInfos != null) {
+ projectLibManage.saveGovSystemReplaceInfos(projectDetail.getId(),
+ projectDetail.getProjectCode(), projectDetail.getSystemReplaceInfos());
+ }
+ LambdaUpdateWrapper wrapper = buildWrapper(projectDiffs, Project.class);
+ if (wrapper != null) {
+ wrapper.eq(Project::getId, projectDetail.getId());
+ projectService.update(wrapper);
+ }
}
List purchases = projectEdit.getPurchases();
if (CollUtil.isNotEmpty(purchases)) {
@@ -242,50 +236,53 @@ public class ProjectChangeStopHelper {
List purchaseDiffs = purchaseEdit.getPurchaseDiffs();
if (CollUtil.isNotEmpty(purchaseDiffs)) {
PurchaseDTO purchaseDetail = purchaseEdit.getPurchase();
- LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate(Purchase.class);
- purchaseDiffs.forEach(fieldDiff -> {
- String fieldName = fieldDiff.getFieldName();
- Object newValue = fieldDiff.getNewValue();
- Function reference = MethodReferenceUtil.getReference(Purchase.class, fieldName);
- if (reference != null) {
- wrapper.set((SFunction) reference, newValue);
- }
- });
- wrapper.eq(Purchase::getId, purchaseDetail.getId());
- purchaseService.update(wrapper);
+ LambdaUpdateWrapper wrapper = buildWrapper(purchaseDiffs, Purchase.class);
+ if (wrapper != null) {
+ wrapper.eq(Purchase::getId, purchaseDetail.getId());
+ purchaseService.update(wrapper);
+ }
}
List contractDiffs = purchaseEdit.getContractDiffs();
if (CollUtil.isNotEmpty(contractDiffs)) {
ContractDTO contractDetail = purchaseEdit.getContract();
- LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate(Contract.class);
- contractDiffs.forEach(fieldDiff -> {
- String fieldName = fieldDiff.getFieldName();
- Object newValue = fieldDiff.getNewValue();
- Function reference = MethodReferenceUtil.getReference(Contract.class, fieldName);
- if (reference != null) {
- wrapper.set((SFunction) reference, newValue);
- }
- });
- wrapper.eq(Contract::getId, contractDetail.getId());
- contractService.update(wrapper);
+ LambdaUpdateWrapper wrapper = buildWrapper(contractDiffs, Contract.class);
+ if (wrapper != null) {
+ wrapper.eq(Contract::getId, contractDetail.getId());
+ contractService.update(wrapper);
+ }
}
List operationDiffs = purchaseEdit.getOperationDiffs();
if (CollUtil.isNotEmpty(operationDiffs)) {
OperationDTO operationDetail = purchaseEdit.getOperation();
- LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate(Operation.class);
- operationDiffs.forEach(fieldDiff -> {
- String fieldName = fieldDiff.getFieldName();
- Object newValue = fieldDiff.getNewValue();
- Function reference = MethodReferenceUtil.getReference(Operation.class, fieldName);
- if (reference != null) {
- wrapper.set((SFunction) reference, newValue);
- }
- });
- wrapper.eq(Operation::getId, operationDetail.getId());
- operationService.update(wrapper);
+ LambdaUpdateWrapper wrapper = buildWrapper(operationDiffs, Operation.class);
+ if (wrapper != null) {
+ wrapper.eq(Operation::getId, operationDetail.getId());
+ operationService.update(wrapper);
+ }
}
}
}
}
+ private LambdaUpdateWrapper buildWrapper(List diffs,
+ Class clazz) {
+ LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate(clazz);
+ boolean hasFieldChanged = false;
+ for (FieldDiff fieldDiff : diffs) {
+ String fieldName = fieldDiff.getFieldName();
+ Object newValue = fieldDiff.getNewValue();
+ SFunction reference = getReference(clazz, fieldName);
+ if (reference != null) {
+ hasFieldChanged = true;
+ wrapper.set(reference, newValue);
+ }
+ }
+ return hasFieldChanged ? wrapper : null;
+ }
+
+
+ private SFunction getReference(Class clazz, String fieldName) {
+ return (SFunction) MethodReferenceUtil.getReference(clazz, fieldName);
+ }
+
}