|
|
@@ -1,7 +1,10 @@ |
|
|
|
package com.hz.pm.api.projectdeclared.manage; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.util.NumberUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Assert; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
@@ -18,24 +21,24 @@ import com.hz.pm.api.projectdeclared.model.entity.Contract; |
|
|
|
import com.hz.pm.api.projectdeclared.model.entity.Purchase; |
|
|
|
import com.hz.pm.api.projectdeclared.model.entity.PurchaseInst; |
|
|
|
import com.hz.pm.api.projectdeclared.model.req.SubmitFinallyInspectedReq; |
|
|
|
import com.hz.pm.api.projectdeclared.model.vo.FinalAcceptProgressStatisticsVO; |
|
|
|
import com.hz.pm.api.projectdeclared.model.vo.FinalAcceptanceVO; |
|
|
|
import com.hz.pm.api.projectdeclared.service.IContractService; |
|
|
|
import com.hz.pm.api.projectdeclared.service.IPurchaseInstService; |
|
|
|
import com.hz.pm.api.projectdeclared.service.IPurchaseService; |
|
|
|
import com.hz.pm.api.projectlib.helper.ProjectManageUtil; |
|
|
|
import com.hz.pm.api.projectlib.model.entity.Project; |
|
|
|
import com.hz.pm.api.projectlib.model.entity.ProjectAnnualPaymentPlan; |
|
|
|
import com.hz.pm.api.projectlib.model.entity.ProjectInst; |
|
|
|
import com.hz.pm.api.projectlib.model.enumeration.status.ProjectStatus; |
|
|
|
import com.hz.pm.api.projectlib.model.enumeration.ProjectTypeNewEnum; |
|
|
|
import com.hz.pm.api.projectlib.model.enumeration.status.ProjectStatus; |
|
|
|
import com.hz.pm.api.projectlib.model.enumeration.status.TenderMainStatus; |
|
|
|
import com.hz.pm.api.projectlib.model.req.ProjectListReq; |
|
|
|
import com.hz.pm.api.projectlib.model.vo.ProjectLibListItemVO; |
|
|
|
import com.hz.pm.api.projectlib.model.vo.TenderListInfoVO; |
|
|
|
import com.hz.pm.api.projectlib.service.IProjectAnnualPaymentPlanService; |
|
|
|
import com.hz.pm.api.projectlib.service.IProjectInstService; |
|
|
|
import com.hz.pm.api.projectlib.service.IProjectService; |
|
|
|
import com.hz.pm.api.sys.manage.ProcessModelManage; |
|
|
|
import com.hz.pm.api.user.helper.MhUnitQueryHelper; |
|
|
|
import com.hz.pm.api.user.security.model.UserFullInfoDTO; |
|
|
|
import com.hz.pm.api.user.security.model.UserInfoDetails; |
|
|
|
import com.hz.pm.api.user.util.LoginUserUtil; |
|
|
@@ -55,9 +58,13 @@ import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.function.BiFunction; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static com.hz.pm.api.user.helper.MhUnitQueryHelper.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Classname FinalAcceptanceManage |
|
|
@@ -78,10 +85,10 @@ public class FinalAcceptanceManage { |
|
|
|
private final ProcessInstanceService processInstanceService; |
|
|
|
private final DeclaredProjectHelper declaredProjectManage; |
|
|
|
private final IContractService contractService; |
|
|
|
private final IProjectAnnualPaymentPlanService projectAnnualPaymentPlanService; |
|
|
|
private final ProjectStateMachineUtil projectStateMachineUtil; |
|
|
|
private final TenderStateMachineUtil tenderStateMachineUtil; |
|
|
|
private final IProjectInstService projectInstService; |
|
|
|
private final MhUnitQueryHelper mhUnitQueryHelper; |
|
|
|
|
|
|
|
//================================================================================================================== |
|
|
|
|
|
|
@@ -89,46 +96,104 @@ public class FinalAcceptanceManage { |
|
|
|
|
|
|
|
static { |
|
|
|
FINAL_INSPECTED_TENDER_STATUS = new ArrayList<>(); |
|
|
|
FINAL_INSPECTED_TENDER_STATUS.add(TenderMainStatus.FINALLY_INSPECTED_FAILED); |
|
|
|
FINAL_INSPECTED_TENDER_STATUS.add(TenderMainStatus.TO_BE_SUBMIT_FINALLY_INSPECTED_APPLY); |
|
|
|
FINAL_INSPECTED_TENDER_STATUS.add(TenderMainStatus.ON_FINALLY_INSPECTED_APPLY); |
|
|
|
FINAL_INSPECTED_TENDER_STATUS.add(TenderMainStatus.FINALLY_INSPECTED_PASSED); |
|
|
|
FINAL_INSPECTED_TENDER_STATUS.add(TenderMainStatus.FINALLY_INSPECTED_FAILED); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 待采购的-项目列表 |
|
|
|
* |
|
|
|
* @param req \ |
|
|
|
* @return \ |
|
|
|
*/ |
|
|
|
public PageVo<ProjectLibListItemVO> projectLibList(ProjectListReq req) { |
|
|
|
|
|
|
|
public FinalAcceptProgressStatisticsVO finalAcceptProgressStatistics(ProjectListReq req) { |
|
|
|
LambdaQueryWrapper<Purchase> purchaseQuery = Wrappers.lambdaQuery(Purchase.class) |
|
|
|
.select(Purchase::getProjectId, Purchase::getStatus) |
|
|
|
.in(Purchase::getStatus, CollUtils.fieldList(FINAL_INSPECTED_TENDER_STATUS, TenderMainStatus::getCode)); |
|
|
|
List<Purchase> purchases = purchaseService.list(purchaseQuery); |
|
|
|
if (purchases.isEmpty()) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
UserInfoDetails user = LoginUserUtil.loginUserDetail(); |
|
|
|
String buildOrgCode = req.getBuildOrgCode(); |
|
|
|
req.setBuildOrgCode(null); |
|
|
|
LambdaQueryWrapper<Project> query = ProjectManageUtil.projectQuery(req); |
|
|
|
//待终验 并且还未过期 |
|
|
|
//只能看自己单位的 |
|
|
|
Long buildOrgCodeNum = NumberUtil.parseLong(buildOrgCode, null); |
|
|
|
UnitQueryState queryState = mhUnitQueryHelper.listCanViewUnitIds(buildOrgCodeNum, user); |
|
|
|
if (!queryState.isState()) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
if (CollUtil.isNotEmpty(queryState.getUnitIds())) { |
|
|
|
query.in(Project::getBuildOrgCode, CollUtils.convert(queryState.getUnitIds(), String::valueOf)); |
|
|
|
} |
|
|
|
query.in(Project::getId, CollUtils.fieldList(purchases, Purchase::getProjectId)) |
|
|
|
.select(Project::getId) |
|
|
|
.eq(Project::getNewest, Boolean.TRUE); |
|
|
|
List<Project> projects = projectService.list(query); |
|
|
|
List<Long> projectIds = CollUtils.fieldList(projects, Project::getId); |
|
|
|
Map<Long, List<Integer>> purchaseStatusMap = purchases.stream() |
|
|
|
.filter(purchase -> projectIds.contains(purchase.getProjectId())) |
|
|
|
.collect(Collectors.groupingBy(Purchase::getProjectId, |
|
|
|
Collectors.mapping(Purchase::getStatus, Collectors.toList()))); |
|
|
|
BiFunction<Map<Long, List<Integer>>, TenderMainStatus, Integer> counter = (statusMap, status) -> { |
|
|
|
Set<Map.Entry<Long, List<Integer>>> entries = statusMap.entrySet(); |
|
|
|
return CollUtil.count(entries, entry -> entry.getValue().contains(status.getCode())); |
|
|
|
}; |
|
|
|
return FinalAcceptProgressStatisticsVO.builder() |
|
|
|
.totalCount(projects.size()) |
|
|
|
.auditCount(counter.apply(purchaseStatusMap, TenderMainStatus.ON_FINALLY_INSPECTED_APPLY)) |
|
|
|
.todoCount(counter.apply(purchaseStatusMap, TenderMainStatus.TO_BE_SUBMIT_FINALLY_INSPECTED_APPLY)) |
|
|
|
.failedCount(counter.apply(purchaseStatusMap, TenderMainStatus.FINALLY_INSPECTED_FAILED)) |
|
|
|
.passedCount(counter.apply(purchaseStatusMap, TenderMainStatus.FINALLY_INSPECTED_PASSED)) |
|
|
|
.build(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 待采购的-项目列表 |
|
|
|
* |
|
|
|
* @param req \ |
|
|
|
* @return \ |
|
|
|
*/ |
|
|
|
public PageVo<ProjectLibListItemVO> projectLibList(ProjectListReq req) { |
|
|
|
Set<Long> projectIds = purchaseService.listProjectIdByStatus(FINAL_INSPECTED_TENDER_STATUS); |
|
|
|
if (projectIds.isEmpty()) { |
|
|
|
return PageVo.empty(); |
|
|
|
} |
|
|
|
if (!user.hasSuperAdmin()) { |
|
|
|
query.eq(Project::getBuildOrgCode, user.getMhUnitIdStr()); |
|
|
|
UserInfoDetails user = LoginUserUtil.loginUserDetail(); |
|
|
|
String buildOrgCode = req.getBuildOrgCode(); |
|
|
|
req.setBuildOrgCode(null); |
|
|
|
LambdaQueryWrapper<Project> query = ProjectManageUtil.projectQuery(req) |
|
|
|
.in(Project::getId, projectIds) |
|
|
|
.eq(Project::getNewest, Boolean.TRUE) |
|
|
|
.orderByAsc(Project::getApprovalDate); |
|
|
|
Long buildOrgCodeNum = NumberUtil.parseLong(buildOrgCode, null); |
|
|
|
UnitQueryState queryState = mhUnitQueryHelper.listCanViewUnitIds(buildOrgCodeNum, user); |
|
|
|
if (!queryState.isState()) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
if (CollUtil.isNotEmpty(queryState.getUnitIds())) { |
|
|
|
query.in(Project::getBuildOrgCode, CollUtils.convert(queryState.getUnitIds(), String::valueOf)); |
|
|
|
} |
|
|
|
query.in(Project::getId, projectIds); |
|
|
|
query.eq(Project::getStage, ProjectStatus.PROJECT_APPROVED.getCode()); |
|
|
|
query.eq(Project::getNewest, Boolean.TRUE); |
|
|
|
query.orderByAsc(Project::getApprovalDate); |
|
|
|
Page<Project> page = projectService.page(req.page(), query); |
|
|
|
if (page.getTotal() == 0) { |
|
|
|
return PageVo.empty(); |
|
|
|
} |
|
|
|
|
|
|
|
Set<Long> allProjectIds = CollUtils.fieldSet(page.getRecords(), Project::getId); |
|
|
|
List<Purchase> purchases = purchaseService.listByProjectIds(allProjectIds); |
|
|
|
Map<Long, List<Purchase>> purchaseMap = CollUtils.group(purchases, Purchase::getProjectId); |
|
|
|
Map<Long, Contract> contractMap = contractService.listByProjectIds(projectIds); |
|
|
|
Map<Long, List<ProjectAnnualPaymentPlan>> paymentPlansMap = projectAnnualPaymentPlanService.listByProjectIds(projectIds); |
|
|
|
|
|
|
|
Wrapper<Purchase> purchaseQuery = Wrappers.lambdaQuery(Purchase.class) |
|
|
|
.in(Purchase::getProjectId, allProjectIds) |
|
|
|
.eq(Purchase::getStatus, req.getTabStatus()); |
|
|
|
List<Purchase> purchases = purchaseService.list(purchaseQuery); |
|
|
|
Map<Long, List<Purchase>> purchaseMap; |
|
|
|
Map<Long, Contract> contractMap; |
|
|
|
if (!purchases.isEmpty()) { |
|
|
|
purchaseMap = CollUtils.group(purchases, Purchase::getProjectId); |
|
|
|
contractMap = contractService.listByProjectIds(projectIds); |
|
|
|
} else { |
|
|
|
purchaseMap = Collections.emptyMap(); |
|
|
|
contractMap = Collections.emptyMap(); |
|
|
|
} |
|
|
|
List<ProjectLibListItemVO> records = CollUtils.convert(page.getRecords(), w -> { |
|
|
|
ProjectLibListItemVO item = new ProjectLibListItemVO(); |
|
|
|
item.setId(w.getId()); |
|
|
@@ -147,13 +212,7 @@ public class FinalAcceptanceManage { |
|
|
|
item.setReviewAmount(w.getReviewAmount()); |
|
|
|
item.setApprovedAmount(w.getApprovalAmount()); |
|
|
|
item.setApprovalDate(w.getApprovalDate()); |
|
|
|
item.setBuildCycle(StringUtils.isNotBlank(w.getBuildCycle()) ? |
|
|
|
Integer.valueOf(w.getBuildCycle()) : null); |
|
|
|
List<ProjectAnnualPaymentPlan> paymentPlans = paymentPlansMap.getOrDefault(w.getId(), Collections.emptyList()); |
|
|
|
BigDecimal totalAnnualAmount = paymentPlans.stream() |
|
|
|
.map(ProjectAnnualPaymentPlan::getAnnualPlanAmount) |
|
|
|
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO); |
|
|
|
item.setAnnualPlanAmount(totalAnnualAmount); |
|
|
|
item.setBuildCycle(StrUtil.isNotBlank(w.getBuildCycle()) ? Integer.valueOf(w.getBuildCycle()) : null); |
|
|
|
item.setPlanAcceptanceTime(w.getPlanAcceptanceTime()); |
|
|
|
List<Purchase> currPurchases = purchaseMap.get(w.getId()); |
|
|
|
if (currPurchases != null) { |
|
|
|