@@ -0,0 +1,66 @@ | |||
package com.hz.pm.api.projectdeclared.chain; | |||
import com.hz.pm.api.common.statemachine.util.ProjectStateMachineUtil; | |||
import com.hz.pm.api.projectdeclared.chain.handler.FinalInspectedPassedHandler; | |||
import com.hz.pm.api.projectdeclared.chain.handler.PurchaseOrgConfirmHandler; | |||
import com.hz.pm.api.projectdeclared.chain.handler.SubmitFinalInspectedHandler; | |||
import com.hz.pm.api.projectdeclared.chain.handler.SubmitFirstInspectedHandler; | |||
import com.hz.pm.api.projectdeclared.chain.request.ProjectStatusRewriteRequest; | |||
import com.hz.pm.api.projectdeclared.model.entity.Purchase; | |||
import com.hz.pm.api.projectdeclared.model.enumerization.BidTypeEnum; | |||
import com.hz.pm.api.projectlib.entity.PurchaseStatusChange; | |||
import com.hz.pm.api.projectlib.model.entity.Project; | |||
import com.hz.pm.api.projectlib.service.IProjectService; | |||
import com.hz.pm.api.projectlib.service.IPurchaseStatusChangeService; | |||
import com.ningdatech.basic.util.CollUtils; | |||
import lombok.RequiredArgsConstructor; | |||
import org.springframework.stereotype.Component; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* ProjectStatusRewriteHandlerContext | |||
* </p> | |||
* | |||
* @author WendyYang | |||
* @since 18:20 2024/10/22 | |||
*/ | |||
@Component | |||
@RequiredArgsConstructor | |||
public class ProjectStatusRewriteHandlerContext { | |||
private final ProjectStateMachineUtil projectStateMachineUtil; | |||
private final IProjectService projectService; | |||
private final IPurchaseStatusChangeService purchaseStatusChangeService; | |||
public void process(Purchase purchase, Project project, List<Purchase> purchases) { | |||
if (!BidTypeEnum.BUILD_APP.eq(purchase.getBidType())) { | |||
List<Long> buildAddBidIds = CollUtils.filter(purchases, w -> BidTypeEnum.BUILD_APP.eq(w.getBidType()), Purchase::getId); | |||
if (!buildAddBidIds.isEmpty()) { | |||
List<PurchaseStatusChange> changes = purchaseStatusChangeService.listByProjectCode(project.getProjectCode(), buildAddBidIds); | |||
Map<Long, List<PurchaseStatusChange>> changeMap = CollUtils.group(changes, PurchaseStatusChange::getBidId); | |||
PurchaseOrgConfirmHandler firstHandler = getFirstHandler(); | |||
ProjectStatusRewriteRequest context = new ProjectStatusRewriteRequest(); | |||
context.setProjectStateMachineUtil(projectStateMachineUtil); | |||
context.setProject(project); | |||
context.setBuildAddBidIds(buildAddBidIds); | |||
context.setPurchaseStatusChangeMap(changeMap); | |||
Integer beforeStatus = project.getStatus(); | |||
firstHandler.handle(context); | |||
if (!beforeStatus.equals(project.getStatus())) { | |||
projectService.updateById(project); | |||
} | |||
} | |||
} | |||
} | |||
private static PurchaseOrgConfirmHandler getFirstHandler() { | |||
FinalInspectedPassedHandler finalInspectedPassedHandler = new FinalInspectedPassedHandler(null); | |||
SubmitFinalInspectedHandler submitFinalInspectedHandler = new SubmitFinalInspectedHandler(finalInspectedPassedHandler); | |||
SubmitFirstInspectedHandler submitFirstInspectedHandler = new SubmitFirstInspectedHandler(submitFinalInspectedHandler); | |||
return new PurchaseOrgConfirmHandler(submitFirstInspectedHandler); | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
package com.hz.pm.api.projectdeclared.chain.handler; | |||
import com.hz.pm.api.common.statemachine.event.AbstractStateChangeEvent; | |||
import com.hz.pm.api.common.statemachine.event.TenderStateChangeEvent; | |||
import com.hz.pm.api.projectdeclared.chain.request.ProjectStatusRewriteRequest; | |||
/** | |||
* <p> | |||
* FinallyInspectedPassedHandler | |||
* </p> | |||
* | |||
* @author WendyYang | |||
* @since 18:44 2024/10/22 | |||
*/ | |||
public class FinalInspectedPassedHandler implements ProjectStatusRewriteHandler { | |||
private final ProjectStatusRewriteHandler nextHandler; | |||
public FinalInspectedPassedHandler(ProjectStatusRewriteHandler nextHandler) { | |||
this.nextHandler = nextHandler; | |||
} | |||
@Override | |||
public AbstractStateChangeEvent getEvent() { | |||
return TenderStateChangeEvent.FINALLY_INSPECTED_PASSED; | |||
} | |||
@Override | |||
public void handle(ProjectStatusRewriteRequest context) { | |||
if (support(context)) { | |||
context.getProjectStateMachineUtil().pass(context.getProject()); | |||
if (nextHandler != null) { | |||
nextHandler.handle(context); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,32 @@ | |||
package com.hz.pm.api.projectdeclared.chain.handler; | |||
import cn.hutool.core.collection.CollUtil; | |||
import com.hz.pm.api.common.statemachine.event.AbstractStateChangeEvent; | |||
import com.hz.pm.api.projectdeclared.chain.request.ProjectStatusRewriteRequest; | |||
import java.util.List; | |||
/** | |||
* <p> | |||
* ProjectStatusRewriteHandler | |||
* </p> | |||
* | |||
* @author WendyYang | |||
* @since 18:42 2024/10/22 | |||
*/ | |||
public interface ProjectStatusRewriteHandler { | |||
AbstractStateChangeEvent getEvent(); | |||
default boolean support(ProjectStatusRewriteRequest context) { | |||
List<Long> buildAddBidIds = context.getBuildAddBidIds(); | |||
long tmpCount = context.getPurchaseStatusChangeMap().entrySet().stream() | |||
.filter(w -> buildAddBidIds.contains(w.getKey())) | |||
.filter(w -> CollUtil.anyMatch(w.getValue(), change -> getEvent().eq(change.getEvent()))) | |||
.count(); | |||
return tmpCount == buildAddBidIds.size(); | |||
} | |||
void handle(ProjectStatusRewriteRequest context); | |||
} |
@@ -0,0 +1,38 @@ | |||
package com.hz.pm.api.projectdeclared.chain.handler; | |||
import com.hz.pm.api.common.statemachine.event.AbstractStateChangeEvent; | |||
import com.hz.pm.api.common.statemachine.event.TenderStateChangeEvent; | |||
import com.hz.pm.api.projectdeclared.chain.request.ProjectStatusRewriteRequest; | |||
/** | |||
* <p> | |||
* PurchaseOrgConfirmHandler | |||
* </p> | |||
* | |||
* @author WendyYang | |||
* @since 18:42 2024/10/22 | |||
*/ | |||
public class PurchaseOrgConfirmHandler implements ProjectStatusRewriteHandler { | |||
private final ProjectStatusRewriteHandler nextHandler; | |||
public PurchaseOrgConfirmHandler(ProjectStatusRewriteHandler nextHandler) { | |||
this.nextHandler = nextHandler; | |||
} | |||
@Override | |||
public AbstractStateChangeEvent getEvent() { | |||
return TenderStateChangeEvent.SUBMIT_PURCHASE_ORG_CONFIRM; | |||
} | |||
@Override | |||
public void handle(ProjectStatusRewriteRequest context) { | |||
if (support(context)) { | |||
context.getProjectStateMachineUtil().pass(context.getProject()); | |||
if (nextHandler != null) { | |||
nextHandler.handle(context); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
package com.hz.pm.api.projectdeclared.chain.handler; | |||
import com.hz.pm.api.common.statemachine.event.AbstractStateChangeEvent; | |||
import com.hz.pm.api.common.statemachine.event.TenderStateChangeEvent; | |||
import com.hz.pm.api.projectdeclared.chain.request.ProjectStatusRewriteRequest; | |||
/** | |||
* <p> | |||
* SubmitFinallyInspectedHandler | |||
* </p> | |||
* | |||
* @author WendyYang | |||
* @since 18:43 2024/10/22 | |||
*/ | |||
public class SubmitFinalInspectedHandler implements ProjectStatusRewriteHandler { | |||
private final ProjectStatusRewriteHandler nextHandler; | |||
public SubmitFinalInspectedHandler(ProjectStatusRewriteHandler nextHandler) { | |||
this.nextHandler = nextHandler; | |||
} | |||
@Override | |||
public AbstractStateChangeEvent getEvent() { | |||
return TenderStateChangeEvent.SUBMIT_FINALLY_INSPECTED; | |||
} | |||
@Override | |||
public void handle(ProjectStatusRewriteRequest context) { | |||
if (support(context)) { | |||
context.getProjectStateMachineUtil().pass(context.getProject()); | |||
if (nextHandler != null) { | |||
nextHandler.handle(context); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
package com.hz.pm.api.projectdeclared.chain.handler; | |||
import com.hz.pm.api.common.statemachine.event.AbstractStateChangeEvent; | |||
import com.hz.pm.api.common.statemachine.event.TenderStateChangeEvent; | |||
import com.hz.pm.api.projectdeclared.chain.request.ProjectStatusRewriteRequest; | |||
/** | |||
* <p> | |||
* SubmitFirstInspectedFilesHandler | |||
* </p> | |||
* | |||
* @author WendyYang | |||
* @since 18:43 2024/10/22 | |||
*/ | |||
public class SubmitFirstInspectedHandler implements ProjectStatusRewriteHandler { | |||
private final ProjectStatusRewriteHandler nextHandler; | |||
public SubmitFirstInspectedHandler(ProjectStatusRewriteHandler nextHandler) { | |||
this.nextHandler = nextHandler; | |||
} | |||
@Override | |||
public AbstractStateChangeEvent getEvent() { | |||
return TenderStateChangeEvent.SUBMIT_FIRST_INSPECTED_FILES; | |||
} | |||
@Override | |||
public void handle(ProjectStatusRewriteRequest context) { | |||
if (support(context)) { | |||
context.getProjectStateMachineUtil().pass(context.getProject()); | |||
if (nextHandler != null) { | |||
nextHandler.handle(context); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.hz.pm.api.projectdeclared.chain.request; | |||
import com.hz.pm.api.common.statemachine.util.ProjectStateMachineUtil; | |||
import com.hz.pm.api.projectlib.entity.PurchaseStatusChange; | |||
import com.hz.pm.api.projectlib.model.entity.Project; | |||
import lombok.Data; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* ProjectStatusRewriteRequest | |||
* </p> | |||
* | |||
* @author WendyYang | |||
* @since 18:15 2024/10/22 | |||
*/ | |||
@Data | |||
public class ProjectStatusRewriteRequest { | |||
private ProjectStateMachineUtil projectStateMachineUtil; | |||
private Project project; | |||
private Map<Long, List<PurchaseStatusChange>> purchaseStatusChangeMap; | |||
private List<Long> buildAddBidIds; | |||
} |
@@ -30,6 +30,7 @@ import com.hz.pm.api.external.model.dto.MhPurchaseIntentionDTO; | |||
import com.hz.pm.api.external.model.dto.MhPurchaseNoticeDTO; | |||
import com.hz.pm.api.external.model.enumeration.MhUnitStripEnum; | |||
import com.hz.pm.api.external.todo.enumerization.MHTodoTypeEnum; | |||
import com.hz.pm.api.projectdeclared.chain.ProjectStatusRewriteHandlerContext; | |||
import com.hz.pm.api.projectdeclared.helper.MhXchxFileHelper; | |||
import com.hz.pm.api.projectdeclared.model.dto.DeclaredProjectExportDTO; | |||
import com.hz.pm.api.projectdeclared.model.dto.PurchaseSaveDTO; | |||
@@ -134,6 +135,7 @@ public class PurchaseManage { | |||
private final MhUnitQueryAuthHelper mhUnitQueryAuthHelper; | |||
private final IProjectGovSystemReplaceInfosService projectGovSystemReplaceInfosService; | |||
private final IProjectStatusChangeService projectStatusChangeService; | |||
private final ProjectStatusRewriteHandlerContext projectStatusRewriteHandlerContext; | |||
public PurchaseProgressStatVO purchaseProgressStatistics(ProjectListReq req) { | |||
UserInfoDetails user = LoginUserUtil.loginUserDetail(); | |||
@@ -633,14 +635,6 @@ public class PurchaseManage { | |||
contract.setSupplierContact(req.getSupplierContact()); | |||
contract.setSupplierContactInfo(req.getSupplierContactInfo()); | |||
contractService.saveOrUpdate(contract); | |||
// 判断是否所有标项都完成了采购合同备案 | |||
Wrapper<Purchase> select = Wrappers.lambdaQuery(Purchase.class) | |||
.select(Purchase::getId, Purchase::getSupplier) | |||
.eq(Purchase::getProjectId, projectId); | |||
List<Purchase> purchases = purchaseService.list(select); | |||
if (CollUtil.allMatch(purchases, w -> StrUtil.isNotBlank(w.getSupplier()))) { | |||
projectStateMachineUtil.pass(project); | |||
} | |||
// 修改项目合同金额 | |||
Wrapper<Contract> query = Wrappers.lambdaQuery(Contract.class) | |||
.eq(Contract::getProjectId, projectId); | |||
@@ -648,7 +642,17 @@ public class PurchaseManage { | |||
BigDecimal totalAmount = DecimalUtil.sum(allContracts, Contract::getTotalAmount); | |||
project.setUpdateOn(now); | |||
project.setContractAmount(totalAmount); | |||
projectService.updateById(project); | |||
// 判断是否所有标项都完成了采购合同备案 | |||
Wrapper<Purchase> select = Wrappers.lambdaQuery(Purchase.class) | |||
.select(Purchase::getId, Purchase::getSupplier, Purchase::getBidType) | |||
.eq(Purchase::getProjectId, projectId); | |||
List<Purchase> purchases = purchaseService.list(select); | |||
if (CollUtil.allMatch(purchases, w -> StrUtil.isNotBlank(w.getSupplier()))) { | |||
projectStateMachineUtil.pass(project); | |||
projectStatusRewriteHandlerContext.process(purchase, project, purchases); | |||
} else { | |||
projectService.updateById(project); | |||
} | |||
SpringUtil.publishEvent(MhTodoHandedEvent.of(MHTodoTypeEnum.WITHOUT_PURCHASE_CONTRACT, purchase.getId())); | |||
SpringUtil.publishEvent(MhTodoSendEvent.of(MHTodoTypeEnum.WITHOUT_OPERATION_PLAN, project, purchase)); | |||
} | |||
@@ -945,7 +945,7 @@ public class ProjectLibManage { | |||
throw ReturnException.wrap("项目状态异常,保存失败"); | |||
} | |||
newProj.setVersion(oldProj.getVersion() + 1); | |||
projectService.reverseNewest(newProj.getProjectCode(), newProj.getId()); | |||
projectService.reverseNewest(reqProj.getProjectCode(), reqProj.getId()); | |||
} | |||
newProj.setId(null); | |||
newProj.setNewest(Boolean.TRUE); | |||
@@ -13,6 +13,7 @@ import com.ningdatech.basic.util.CollUtils; | |||
import java.util.Collection; | |||
import java.util.Comparator; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
@@ -42,4 +43,12 @@ public interface IPurchaseStatusChangeService extends IService<PurchaseStatusCha | |||
Comparator.comparing(PurchaseStatusChange::getCreateOn).reversed()); | |||
} | |||
default List<PurchaseStatusChange> listByProjectCode(String projectCode, Collection<Long> bidIds) { | |||
LambdaQueryWrapper<PurchaseStatusChange> pscQuery = Wrappers.lambdaQuery(PurchaseStatusChange.class) | |||
.eq(PurchaseStatusChange::getProjectCode, projectCode) | |||
.in(PurchaseStatusChange::getBidId, bidIds) | |||
.orderByDesc(PurchaseStatusChange::getCreateOn); | |||
return list(pscQuery); | |||
} | |||
} |
@@ -337,11 +337,13 @@ public class WorkbenchManage { | |||
Map<Long, List<Purchase>> projectPurchaseCountMap = new HashMap<>(); | |||
BiFunction<AbstractStateChangeEvent, WorkbenchProcessNode, List<Long>> computeProjectIds = (event, node) -> { | |||
Map<Long, Long> projBizMap = purchaseEventMap.getOrDefault(event.name(), Collections.emptyMap()); | |||
if (node.equals(WorkbenchProcessNode.PROJECT_ADAPTION)) { | |||
if (node.equals(WorkbenchProcessNode.PROJECT_ADAPTION) | |||
|| node.equals(WorkbenchProcessNode.FIRST_INSPECTED) | |||
|| node.equals(WorkbenchProcessNode.FINAL_INSPECTED)) { | |||
return projectPurchaseCountMap.entrySet().stream().filter(w -> { | |||
Long finishedBizCount = projBizMap.get(w.getKey()); | |||
return finishedBizCount != null && finishedBizCount == CollUtil.count(w.getValue(), | |||
x -> BidTypeEnum.BUILD_APP.eq(x.getBidType())); | |||
return finishedBizCount != null && finishedBizCount > 0 | |||
&& finishedBizCount == CollUtil.count(w.getValue(), x -> BidTypeEnum.BUILD_APP.eq(x.getBidType())); | |||
}).map(Map.Entry::getKey).collect(Collectors.toList()); | |||
} else { | |||
return projectPurchaseCountMap.entrySet().stream().filter(w -> { | |||
@@ -350,6 +352,7 @@ public class WorkbenchManage { | |||
}).map(Map.Entry::getKey).collect(Collectors.toList()); | |||
} | |||
}; | |||
// 查询完成立项备案的项目 | |||
List<Long> viewUnitIds = mhUnitCache.getViewChildIdsRecursion(req.getUnitId()); | |||
Wrapper<Project> query = Wrappers.lambdaQuery(Project.class) | |||
@@ -502,22 +505,24 @@ public class WorkbenchManage { | |||
} | |||
break; | |||
case FIRST_INSPECTED: { | |||
List<Long> projectIds = computeProjectIds.apply(TenderStateChangeEvent.SUBMIT_FIRST_INSPECTED_FILES, node); | |||
Pair<Integer, Integer> replaceSystemCount = countReplaceSystemByProjectIds(projectIds); | |||
currStat.setProjectCount(projectIds.size()); | |||
List<String> projectCodes = CollUtils.filter(projectStatusChangeMap.entrySet(), | |||
w -> CollUtil.anyMatch(w.getValue(), w1 -> ProjectStateChangeEvent.SUBMIT_FIRST_INSPECTED_FILES.eq(w1.getEvent())), | |||
Map.Entry::getKey); | |||
Pair<Integer, Integer> replaceSystemCount = countReplaceSystemByProjectCodes(projectCodes); | |||
currStat.setProjectCount(projectCodes.size()); | |||
currStat.setSourceCount(replaceSystemCount.getKey()); | |||
currStat.setTargetCount(replaceSystemCount.getValue()); | |||
List<String> projectCodes = CollUtils.convert(projectIds, ProjectIdCodeCacheUtil::get); | |||
currStat.setStoppedCount(stoppedProjectCount(projectStatusChangeMap, projectCodes)); | |||
} | |||
break; | |||
case FINAL_INSPECTED: { | |||
List<Long> projectIds = computeProjectIds.apply(TenderStateChangeEvent.FINALLY_INSPECTED_PASSED, node); | |||
Pair<Integer, Integer> replaceSystemCount = countReplaceSystemByProjectIds(projectIds); | |||
currStat.setProjectCount(projectIds.size()); | |||
List<String> projectCodes = CollUtils.filter(projectStatusChangeMap.entrySet(), | |||
w -> CollUtil.anyMatch(w.getValue(), w1 -> ProjectStateChangeEvent.FINAL_ACCEPTANCE_PASS.eq(w1.getEvent())), | |||
Map.Entry::getKey); | |||
Pair<Integer, Integer> replaceSystemCount = countReplaceSystemByProjectCodes(projectCodes); | |||
currStat.setProjectCount(projectCodes.size()); | |||
currStat.setSourceCount(replaceSystemCount.getKey()); | |||
currStat.setTargetCount(replaceSystemCount.getValue()); | |||
List<String> projectCodes = CollUtils.convert(projectIds, ProjectIdCodeCacheUtil::get); | |||
currStat.setStoppedCount(stoppedProjectCount(projectStatusChangeMap, projectCodes)); | |||
} | |||
break; | |||