|
|
@@ -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; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
@@ -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<FieldDiff> projectDiffs = projectEdit.getProjectDiffs(); |
|
|
|
if (projectDiffs != null && !projectDiffs.isEmpty()) { |
|
|
|
ProjectDTO projectDetail = projectEdit.getProject(); |
|
|
|
LambdaUpdateWrapper<Project> wrapper = Wrappers.lambdaUpdate(Project.class); |
|
|
|
projectDiffs.forEach(fieldDiff -> { |
|
|
|
String fieldName = fieldDiff.getFieldName(); |
|
|
|
Object newValue = fieldDiff.getNewValue(); |
|
|
|
Function<Project, Object> reference = MethodReferenceUtil.getReference(Project.class, fieldName); |
|
|
|
if (reference != null) { |
|
|
|
wrapper.set((SFunction<Project, Object>) 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<Project> wrapper = buildWrapper(projectDiffs, Project.class); |
|
|
|
if (wrapper != null) { |
|
|
|
wrapper.eq(Project::getId, projectDetail.getId()); |
|
|
|
projectService.update(wrapper); |
|
|
|
} |
|
|
|
} |
|
|
|
List<PurchaseEditDTO> purchases = projectEdit.getPurchases(); |
|
|
|
if (CollUtil.isNotEmpty(purchases)) { |
|
|
@@ -242,50 +236,53 @@ public class ProjectChangeStopHelper { |
|
|
|
List<FieldDiff> purchaseDiffs = purchaseEdit.getPurchaseDiffs(); |
|
|
|
if (CollUtil.isNotEmpty(purchaseDiffs)) { |
|
|
|
PurchaseDTO purchaseDetail = purchaseEdit.getPurchase(); |
|
|
|
LambdaUpdateWrapper<Purchase> wrapper = Wrappers.lambdaUpdate(Purchase.class); |
|
|
|
purchaseDiffs.forEach(fieldDiff -> { |
|
|
|
String fieldName = fieldDiff.getFieldName(); |
|
|
|
Object newValue = fieldDiff.getNewValue(); |
|
|
|
Function<Purchase, Object> reference = MethodReferenceUtil.getReference(Purchase.class, fieldName); |
|
|
|
if (reference != null) { |
|
|
|
wrapper.set((SFunction<Purchase, Object>) reference, newValue); |
|
|
|
} |
|
|
|
}); |
|
|
|
wrapper.eq(Purchase::getId, purchaseDetail.getId()); |
|
|
|
purchaseService.update(wrapper); |
|
|
|
LambdaUpdateWrapper<Purchase> wrapper = buildWrapper(purchaseDiffs, Purchase.class); |
|
|
|
if (wrapper != null) { |
|
|
|
wrapper.eq(Purchase::getId, purchaseDetail.getId()); |
|
|
|
purchaseService.update(wrapper); |
|
|
|
} |
|
|
|
} |
|
|
|
List<FieldDiff> contractDiffs = purchaseEdit.getContractDiffs(); |
|
|
|
if (CollUtil.isNotEmpty(contractDiffs)) { |
|
|
|
ContractDTO contractDetail = purchaseEdit.getContract(); |
|
|
|
LambdaUpdateWrapper<Contract> wrapper = Wrappers.lambdaUpdate(Contract.class); |
|
|
|
contractDiffs.forEach(fieldDiff -> { |
|
|
|
String fieldName = fieldDiff.getFieldName(); |
|
|
|
Object newValue = fieldDiff.getNewValue(); |
|
|
|
Function<Contract, Object> reference = MethodReferenceUtil.getReference(Contract.class, fieldName); |
|
|
|
if (reference != null) { |
|
|
|
wrapper.set((SFunction<Contract, Object>) reference, newValue); |
|
|
|
} |
|
|
|
}); |
|
|
|
wrapper.eq(Contract::getId, contractDetail.getId()); |
|
|
|
contractService.update(wrapper); |
|
|
|
LambdaUpdateWrapper<Contract> wrapper = buildWrapper(contractDiffs, Contract.class); |
|
|
|
if (wrapper != null) { |
|
|
|
wrapper.eq(Contract::getId, contractDetail.getId()); |
|
|
|
contractService.update(wrapper); |
|
|
|
} |
|
|
|
} |
|
|
|
List<FieldDiff> operationDiffs = purchaseEdit.getOperationDiffs(); |
|
|
|
if (CollUtil.isNotEmpty(operationDiffs)) { |
|
|
|
OperationDTO operationDetail = purchaseEdit.getOperation(); |
|
|
|
LambdaUpdateWrapper<Operation> wrapper = Wrappers.lambdaUpdate(Operation.class); |
|
|
|
operationDiffs.forEach(fieldDiff -> { |
|
|
|
String fieldName = fieldDiff.getFieldName(); |
|
|
|
Object newValue = fieldDiff.getNewValue(); |
|
|
|
Function<Operation, Object> reference = MethodReferenceUtil.getReference(Operation.class, fieldName); |
|
|
|
if (reference != null) { |
|
|
|
wrapper.set((SFunction<Operation, Object>) reference, newValue); |
|
|
|
} |
|
|
|
}); |
|
|
|
wrapper.eq(Operation::getId, operationDetail.getId()); |
|
|
|
operationService.update(wrapper); |
|
|
|
LambdaUpdateWrapper<Operation> wrapper = buildWrapper(operationDiffs, Operation.class); |
|
|
|
if (wrapper != null) { |
|
|
|
wrapper.eq(Operation::getId, operationDetail.getId()); |
|
|
|
operationService.update(wrapper); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private <T> LambdaUpdateWrapper<T> buildWrapper(List<FieldDiff> diffs, |
|
|
|
Class<T> clazz) { |
|
|
|
LambdaUpdateWrapper<T> wrapper = Wrappers.lambdaUpdate(clazz); |
|
|
|
boolean hasFieldChanged = false; |
|
|
|
for (FieldDiff fieldDiff : diffs) { |
|
|
|
String fieldName = fieldDiff.getFieldName(); |
|
|
|
Object newValue = fieldDiff.getNewValue(); |
|
|
|
SFunction<T, Object> reference = getReference(clazz, fieldName); |
|
|
|
if (reference != null) { |
|
|
|
hasFieldChanged = true; |
|
|
|
wrapper.set(reference, newValue); |
|
|
|
} |
|
|
|
} |
|
|
|
return hasFieldChanged ? wrapper : null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private <T> SFunction<T, Object> getReference(Class<T> clazz, String fieldName) { |
|
|
|
return (SFunction<T, Object>) MethodReferenceUtil.getReference(clazz, fieldName); |
|
|
|
} |
|
|
|
|
|
|
|
} |