|
@@ -1,15 +1,17 @@ |
|
|
package com.hz.pm.api.projectlib.helper; |
|
|
package com.hz.pm.api.projectlib.helper; |
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
|
import cn.hutool.core.util.ClassUtil; |
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.json.JSONUtil; |
|
|
import cn.hutool.json.JSONUtil; |
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; |
|
|
|
|
|
import com.hz.pm.api.common.model.constant.BizConst; |
|
|
import com.hz.pm.api.common.model.constant.BizConst; |
|
|
import com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent; |
|
|
import com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent; |
|
|
import com.hz.pm.api.common.statemachine.event.TenderStateChangeEvent; |
|
|
import com.hz.pm.api.common.statemachine.event.TenderStateChangeEvent; |
|
|
import com.hz.pm.api.common.util.MethodReferenceUtil; |
|
|
|
|
|
|
|
|
import com.hz.pm.api.common.util.BizUtils; |
|
|
import com.hz.pm.api.projectdeclared.entity.ProjectChangeHistory; |
|
|
import com.hz.pm.api.projectdeclared.entity.ProjectChangeHistory; |
|
|
import com.hz.pm.api.projectdeclared.model.dto.*; |
|
|
import com.hz.pm.api.projectdeclared.model.dto.*; |
|
|
import com.hz.pm.api.projectdeclared.model.entity.Contract; |
|
|
import com.hz.pm.api.projectdeclared.model.entity.Contract; |
|
@@ -35,9 +37,9 @@ import lombok.RequiredArgsConstructor; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* <p> |
|
|
* <p> |
|
@@ -124,20 +126,22 @@ public class ProjectChangeStopHelper { |
|
|
} else { |
|
|
} else { |
|
|
throw new BizException("不支持的状态转换"); |
|
|
throw new BizException("不支持的状态转换"); |
|
|
} |
|
|
} |
|
|
resetProjectPurchaseStatus(project, event, beforeEvent, tenderBeforeEvent, tenderEvent); |
|
|
|
|
|
|
|
|
resetProjectPurchaseStatus(project.getId(), project.getProjectCode(), event, beforeEvent, tenderBeforeEvent, tenderEvent); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void resetProjectPurchaseStatus(Project project, |
|
|
|
|
|
|
|
|
private void resetProjectPurchaseStatus(Long projectId, String projectCode, |
|
|
ProjectStateChangeEvent projEvent, |
|
|
ProjectStateChangeEvent projEvent, |
|
|
ProjectStateChangeEvent projBeforeEvent, |
|
|
ProjectStateChangeEvent projBeforeEvent, |
|
|
TenderStateChangeEvent tenderBeforeEvent, |
|
|
TenderStateChangeEvent tenderBeforeEvent, |
|
|
TenderStateChangeEvent tenderEvent) { |
|
|
TenderStateChangeEvent tenderEvent) { |
|
|
|
|
|
LambdaUpdateWrapper<Project> projectWrapper = Wrappers.lambdaUpdate(Project.class) |
|
|
|
|
|
.eq(Project::getId, projectId); |
|
|
if (projBeforeEvent != null) { |
|
|
if (projBeforeEvent != null) { |
|
|
if (projEvent.equals(ProjectStateChangeEvent.STOPPED_APPLY_FAILED)) { |
|
|
if (projEvent.equals(ProjectStateChangeEvent.STOPPED_APPLY_FAILED)) { |
|
|
project.setStoppedStatus(buildBizStatus(projEvent).getCode()); |
|
|
|
|
|
|
|
|
projectWrapper.set(Project::getStoppedStatus, buildBizStatus(projEvent).getCode()); |
|
|
} else { |
|
|
} else { |
|
|
Wrapper<ProjectChangeHistory> changeHistoryWrapper = Wrappers.lambdaQuery(ProjectChangeHistory.class) |
|
|
Wrapper<ProjectChangeHistory> changeHistoryWrapper = Wrappers.lambdaQuery(ProjectChangeHistory.class) |
|
|
.eq(ProjectChangeHistory::getProjectCode, project.getProjectCode()) |
|
|
|
|
|
|
|
|
.eq(ProjectChangeHistory::getProjectCode, projectCode) |
|
|
.orderByDesc(ProjectChangeHistory::getCreateOn) |
|
|
.orderByDesc(ProjectChangeHistory::getCreateOn) |
|
|
.last(BizConst.LIMIT_1); |
|
|
.last(BizConst.LIMIT_1); |
|
|
ProjectChangeHistory changeHistory = projectChangeHistoryService.getOne(changeHistoryWrapper); |
|
|
ProjectChangeHistory changeHistory = projectChangeHistoryService.getOne(changeHistoryWrapper); |
|
@@ -147,26 +151,27 @@ public class ProjectChangeStopHelper { |
|
|
projectEditRewrite(JSONUtil.toBean(changeHistory.getChangeContent(), ProjectEditDTO.class)); |
|
|
projectEditRewrite(JSONUtil.toBean(changeHistory.getChangeContent(), ProjectEditDTO.class)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
ProjectStatusChange change = projectStatusChangeService.getLastOne(projBeforeEvent, project.getId()); |
|
|
|
|
|
|
|
|
ProjectStatusChange change = projectStatusChangeService.getLastOne(projBeforeEvent, projectId); |
|
|
projectStatusChangeService.save(ProjectStatusChange.builder() |
|
|
projectStatusChangeService.save(ProjectStatusChange.builder() |
|
|
.event(projEvent.name()) |
|
|
.event(projEvent.name()) |
|
|
.projectId(project.getId()) |
|
|
|
|
|
|
|
|
.projectId(projectId) |
|
|
.event(projEvent.name()) |
|
|
.event(projEvent.name()) |
|
|
.projectCode(project.getProjectCode()) |
|
|
|
|
|
|
|
|
.projectCode(projectCode) |
|
|
.beforeStatus(change.getAfterStatus()) |
|
|
.beforeStatus(change.getAfterStatus()) |
|
|
.afterStatus(change.getBeforeStatus()) |
|
|
.afterStatus(change.getBeforeStatus()) |
|
|
.createOn(project.getCreateOn()) |
|
|
|
|
|
.build()); |
|
|
.build()); |
|
|
project.setStatus(change.getBeforeStatus()); |
|
|
|
|
|
project.setStage(ProjectStatus.getNoNull(project.getStatus()).getStage().getCode()); |
|
|
|
|
|
projectService.updateById(project); |
|
|
|
|
|
List<Purchase> purchases = purchaseService.listByProjectId(project.getId()); |
|
|
|
|
|
|
|
|
Integer currStatus = change.getBeforeStatus(); |
|
|
|
|
|
projectWrapper.set(Project::getStatus, currStatus); |
|
|
|
|
|
projectWrapper.set(Project::getStage, ProjectStatus.getNoNull(currStatus).getStage().getCode()); |
|
|
|
|
|
projectService.update(projectWrapper); |
|
|
|
|
|
List<Purchase> purchases = purchaseService.listByProjectId(projectId); |
|
|
if (!purchases.isEmpty()) { |
|
|
if (!purchases.isEmpty()) { |
|
|
Wrapper<PurchaseStatusChange> purchaseStatusChangeQuery = Wrappers.lambdaQuery(PurchaseStatusChange.class) |
|
|
Wrapper<PurchaseStatusChange> purchaseStatusChangeQuery = Wrappers.lambdaQuery(PurchaseStatusChange.class) |
|
|
.eq(PurchaseStatusChange::getProjectId, project.getId()) |
|
|
|
|
|
|
|
|
.eq(PurchaseStatusChange::getProjectId, projectId) |
|
|
.eq(PurchaseStatusChange::getEvent, tenderBeforeEvent); |
|
|
.eq(PurchaseStatusChange::getEvent, tenderBeforeEvent); |
|
|
List<PurchaseStatusChange> purchaseStatusChanges = purchaseStatusChangeService.list(purchaseStatusChangeQuery); |
|
|
List<PurchaseStatusChange> purchaseStatusChanges = purchaseStatusChangeService.list(purchaseStatusChangeQuery); |
|
|
Map<Long, PurchaseStatusChange> purchaseStatusChangeMap = CollUtils.listToMap(purchaseStatusChanges, PurchaseStatusChange::getBidId); |
|
|
|
|
|
|
|
|
Map<Long, PurchaseStatusChange> purchaseStatusChangeMap = BizUtils.groupFirstMap(purchaseStatusChanges, |
|
|
|
|
|
PurchaseStatusChange::getBidId, Comparator.comparing(PurchaseStatusChange::getCreateOn).reversed()); |
|
|
List<PurchaseStatusChange> changeArrayList = new ArrayList<>(); |
|
|
List<PurchaseStatusChange> changeArrayList = new ArrayList<>(); |
|
|
purchases.forEach(purchase -> { |
|
|
purchases.forEach(purchase -> { |
|
|
PurchaseStatusChange currChange = purchaseStatusChangeMap.get(purchase.getId()); |
|
|
PurchaseStatusChange currChange = purchaseStatusChangeMap.get(purchase.getId()); |
|
@@ -176,8 +181,8 @@ public class ProjectChangeStopHelper { |
|
|
.beforeStatus(currChange.getAfterStatus()) |
|
|
.beforeStatus(currChange.getAfterStatus()) |
|
|
.bidId(purchase.getId()) |
|
|
.bidId(purchase.getId()) |
|
|
.event(tenderEvent.name()) |
|
|
.event(tenderEvent.name()) |
|
|
.projectId(project.getId()) |
|
|
|
|
|
.projectCode(project.getProjectCode()) |
|
|
|
|
|
|
|
|
.projectId(projectId) |
|
|
|
|
|
.projectCode(projectCode) |
|
|
.build()); |
|
|
.build()); |
|
|
}); |
|
|
}); |
|
|
purchaseService.updateBatchById(purchases); |
|
|
purchaseService.updateBatchById(purchases); |
|
@@ -227,9 +232,9 @@ public class ProjectChangeStopHelper { |
|
|
projectLibManage.saveGovSystemReplaceInfos(projectDetail.getId(), |
|
|
projectLibManage.saveGovSystemReplaceInfos(projectDetail.getId(), |
|
|
projectDetail.getProjectCode(), projectDetail.getSystemReplaceInfos()); |
|
|
projectDetail.getProjectCode(), projectDetail.getSystemReplaceInfos()); |
|
|
} |
|
|
} |
|
|
LambdaUpdateWrapper<Project> wrapper = buildWrapper(projectDiffs, Project.class); |
|
|
|
|
|
|
|
|
UpdateWrapper<Project> wrapper = buildWrapper(projectDiffs, Project.class); |
|
|
if (wrapper != null) { |
|
|
if (wrapper != null) { |
|
|
wrapper.eq(Project::getId, projectDetail.getId()); |
|
|
|
|
|
|
|
|
wrapper.eq("id", projectDetail.getId()); |
|
|
projectService.update(wrapper); |
|
|
projectService.update(wrapper); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@@ -239,27 +244,27 @@ public class ProjectChangeStopHelper { |
|
|
List<FieldDiff> purchaseDiffs = purchaseEdit.getPurchaseDiffs(); |
|
|
List<FieldDiff> purchaseDiffs = purchaseEdit.getPurchaseDiffs(); |
|
|
if (CollUtil.isNotEmpty(purchaseDiffs)) { |
|
|
if (CollUtil.isNotEmpty(purchaseDiffs)) { |
|
|
PurchaseDTO purchaseDetail = purchaseEdit.getPurchase(); |
|
|
PurchaseDTO purchaseDetail = purchaseEdit.getPurchase(); |
|
|
LambdaUpdateWrapper<Purchase> wrapper = buildWrapper(purchaseDiffs, Purchase.class); |
|
|
|
|
|
|
|
|
UpdateWrapper<Purchase> wrapper = buildWrapper(purchaseDiffs, Purchase.class); |
|
|
if (wrapper != null) { |
|
|
if (wrapper != null) { |
|
|
wrapper.eq(Purchase::getId, purchaseDetail.getId()); |
|
|
|
|
|
|
|
|
wrapper.eq("id", purchaseDetail.getId()); |
|
|
purchaseService.update(wrapper); |
|
|
purchaseService.update(wrapper); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
List<FieldDiff> contractDiffs = purchaseEdit.getContractDiffs(); |
|
|
List<FieldDiff> contractDiffs = purchaseEdit.getContractDiffs(); |
|
|
if (CollUtil.isNotEmpty(contractDiffs)) { |
|
|
if (CollUtil.isNotEmpty(contractDiffs)) { |
|
|
ContractDTO contractDetail = purchaseEdit.getContract(); |
|
|
ContractDTO contractDetail = purchaseEdit.getContract(); |
|
|
LambdaUpdateWrapper<Contract> wrapper = buildWrapper(contractDiffs, Contract.class); |
|
|
|
|
|
|
|
|
UpdateWrapper<Contract> wrapper = buildWrapper(contractDiffs, Contract.class); |
|
|
if (wrapper != null) { |
|
|
if (wrapper != null) { |
|
|
wrapper.eq(Contract::getId, contractDetail.getId()); |
|
|
|
|
|
|
|
|
wrapper.eq("id", contractDetail.getId()); |
|
|
contractService.update(wrapper); |
|
|
contractService.update(wrapper); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
List<FieldDiff> operationDiffs = purchaseEdit.getOperationDiffs(); |
|
|
List<FieldDiff> operationDiffs = purchaseEdit.getOperationDiffs(); |
|
|
if (CollUtil.isNotEmpty(operationDiffs)) { |
|
|
if (CollUtil.isNotEmpty(operationDiffs)) { |
|
|
OperationDTO operationDetail = purchaseEdit.getOperation(); |
|
|
OperationDTO operationDetail = purchaseEdit.getOperation(); |
|
|
LambdaUpdateWrapper<Operation> wrapper = buildWrapper(operationDiffs, Operation.class); |
|
|
|
|
|
|
|
|
UpdateWrapper<Operation> wrapper = buildWrapper(operationDiffs, Operation.class); |
|
|
if (wrapper != null) { |
|
|
if (wrapper != null) { |
|
|
wrapper.eq(Operation::getId, operationDetail.getId()); |
|
|
|
|
|
|
|
|
wrapper.eq("id", operationDetail.getId()); |
|
|
operationService.update(wrapper); |
|
|
operationService.update(wrapper); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@@ -267,25 +272,21 @@ public class ProjectChangeStopHelper { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private <T> LambdaUpdateWrapper<T> buildWrapper(List<FieldDiff> diffs, |
|
|
|
|
|
Class<T> clazz) { |
|
|
|
|
|
LambdaUpdateWrapper<T> wrapper = Wrappers.lambdaUpdate(clazz); |
|
|
|
|
|
|
|
|
private <T> UpdateWrapper<T> buildWrapper(List<FieldDiff> diffs, Class<T> clazz) { |
|
|
|
|
|
List<String> fields = Arrays.stream(ClassUtil.getDeclaredFields(clazz)) |
|
|
|
|
|
.map(Field::getName) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
UpdateWrapper<T> wrapper = Wrappers.update(); |
|
|
boolean hasFieldChanged = false; |
|
|
boolean hasFieldChanged = false; |
|
|
for (FieldDiff fieldDiff : diffs) { |
|
|
for (FieldDiff fieldDiff : diffs) { |
|
|
String fieldName = fieldDiff.getFieldName(); |
|
|
String fieldName = fieldDiff.getFieldName(); |
|
|
Object newValue = fieldDiff.getNewValue(); |
|
|
Object newValue = fieldDiff.getNewValue(); |
|
|
SFunction<T, Object> reference = getReference(clazz, fieldName); |
|
|
|
|
|
if (reference != null) { |
|
|
|
|
|
|
|
|
if (fields.contains(fieldName)) { |
|
|
hasFieldChanged = true; |
|
|
hasFieldChanged = true; |
|
|
wrapper.set(reference, newValue); |
|
|
|
|
|
|
|
|
wrapper.set(StrUtil.toUnderlineCase(fieldName), newValue); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return hasFieldChanged ? wrapper : null; |
|
|
return hasFieldChanged ? wrapper : null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private <T> SFunction<T, Object> getReference(Class<T> clazz, String fieldName) { |
|
|
|
|
|
return (SFunction<T, Object>) MethodReferenceUtil.getReference(clazz, fieldName); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |