Browse Source

信创审核列表 金额查询问题

tags/24080901
PoffyZhang 4 months ago
parent
commit
229f100b14
3 changed files with 152 additions and 104 deletions
  1. +4
    -100
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java
  2. +11
    -4
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/service/IPurchaseService.java
  3. +137
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/service/impl/PurchaseServiceImpl.java

+ 4
- 100
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java View File

@@ -1,7 +1,6 @@
package com.hz.pm.api.projectdeclared.manage;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.FileUtil;
@@ -16,7 +15,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hz.pm.api.common.enumeration.ProjectProcessType;
import com.hz.pm.api.common.helper.UserInfoHelper;
import com.hz.pm.api.common.statemachine.event.AbstractStateChangeEvent;
@@ -25,8 +23,6 @@ import com.hz.pm.api.common.statemachine.event.SelfTestStateChangeEvent;
import com.hz.pm.api.common.statemachine.event.TestValidStateChangeEvent;
import com.hz.pm.api.common.statemachine.util.*;
import com.hz.pm.api.common.util.*;
import com.hz.pm.api.datascope.model.DataScopeDTO;
import com.hz.pm.api.datascope.utils.DataScopeUtil;
import com.hz.pm.api.external.MhApiClient;
import com.hz.pm.api.external.MhFileClient;
import com.hz.pm.api.external.model.dto.MhPurchaseIntentionDTO;
@@ -60,13 +56,11 @@ import com.hz.pm.api.projectlib.service.IProjectInstService;
import com.hz.pm.api.projectlib.service.IProjectService;
import com.hz.pm.api.projectlib.service.IPurchaseStatusChangeService;
import com.hz.pm.api.sys.manage.ProcessModelManage;
import com.hz.pm.api.user.helper.MhUnitCache;
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;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.function.VUtils;
import com.ningdatech.basic.model.ApiResponse;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.basic.util.CollUtils;
import com.ningdatech.basic.util.NdDateUtils;
@@ -79,16 +73,11 @@ import com.wflow.workflow.bean.vo.ProcessStartParamsVo;
import com.wflow.workflow.service.ProcessInstanceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -121,7 +110,6 @@ public class PurchaseManage {
private final MhApiClient mhApiClient;
private final MhFileClient mhFileClient;
private final FileService fileService;
private final MhUnitCache mhUnitCache;
private final IOperationService operationService;
private final ProcessModelManage processModelManage;
private final DeclaredProjectHelper declaredProjectManage;
@@ -138,41 +126,6 @@ public class PurchaseManage {

private final MhXchxFileHelper mhXchxFileHelper;

private boolean buildPurchaseQueryPermission(LambdaQueryWrapper<Purchase> query, UserFullInfoDTO user) {
boolean queryState = true;
Optional<DataScopeDTO> datascope = DataScopeUtil.getCurrentUserDataScopeHasUserId(user);
if (!datascope.isPresent()) {
log.warn("没有取到权限信息 当前查询 没有权限条件");
queryState = false;
} else {
final String existsSql = "select 1 from nd_project np where np.id = nd_purchase.project_id and np.build_org_code";
switch (datascope.get().getRole()) {
case NORMAL_MEMBER:
//普通用户 只能看到自己单位去申报的
query.exists(String.format("%s = '%s'", existsSql, user.getMhUnitIdStr()));
break;
case COMPANY_MANAGER:
List<Long> childUnitIds = mhUnitCache.getViewChildIdsRecursion(user.getMhUnitId());
List<String> viewUnitIdList = CollUtils.convert(childUnitIds, String::valueOf);
query.exists(String.format("%s in %s", existsSql, BizUtils.inSqlJoin(viewUnitIdList)));
break;
case SUPER_ADMIN:
// 超级管理员 看到全市的 并且也要判断他 同时是不是单位管理员
break;
case VISITOR:
//访客可以看全市的
break;
case DASHBOARD:
break;
default:
//没有权限的话 就让它查不到
queryState = false;
break;
}
}
return queryState;
}

/**
* 待采购的-项目列表
*
@@ -479,7 +432,7 @@ public class PurchaseManage {
query.ne(Purchase::getBidType, BidTypeEnum.BUILD_APP.getCode()).notExists(existsSql);
}
UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
if (!buildPurchaseQueryPermission(query, user)) {
if (!purchaseService.buildPurchaseQueryPermission(query, user)) {
return PageVo.empty();
}
Page<Purchase> page = purchaseService.page(req.page(), query);
@@ -714,62 +667,13 @@ public class PurchaseManage {
Integer pageSize = req.getPageSize();
//手动添加的
List<XcfhxApplyListVO> manuals = xinchuangService.listXcfhxApplyListVO(req);
//系统和大数据推送的
List<XcfhxApplyListVO> others = purchaseService.listXcfhxApplyListVO(req);

LambdaQueryWrapper<Purchase> query = Wrappers.lambdaQuery(Purchase.class)
.like(StrUtil.isNotBlank(req.getBidName()), Purchase::getBidName, req.getBidName())
.le(req.getCreateOnMax() != null, Purchase::getCreateOn, req.getCreateOnMax())
.ge(req.getCreateOnMin() != null, Purchase::getCreateOn, req.getCreateOnMin())
.eq(req.getStatus() != null, Purchase::getXcfhxApplyStatus, req.getStatus())
.eq(req.getSourceType() != null,Purchase::getSourceType,req.getSourceType())
.ge(Objects.nonNull(req.getAmountStart()),Purchase::getTransactionAmount,req.getAmountStart())
.le(Objects.nonNull(req.getAmountEnd()),Purchase::getTransactionAmount,req.getAmountEnd())
.orderByDesc(Purchase::getCreateOn);

if (Boolean.TRUE.equals(req.getFinished())) {
query.eq(Purchase::getXcfhxApplyStatus, TenderXcfhxApplyStatus.XCFHX_APPLY_PASSED.getCode());
} else if (Boolean.FALSE.equals(req.getFinished())){
query.ne(Purchase::getXcfhxApplyStatus, TenderXcfhxApplyStatus.XCFHX_APPLY_PASSED.getCode());
}
UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
if (!buildPurchaseQueryPermission(query, user)) {
return PageVo.empty();
}
List<Purchase> purchases = purchaseService.list(query);
List<XcfhxApplyListVO> others = Lists.newArrayList();
if (CollUtil.isNotEmpty(purchases)) {
Set<Long> projectIds = CollUtils.fieldSet(purchases, Purchase::getProjectId);
List<Project> projects = projectIds.isEmpty() ? Lists.newArrayList() : projectService.list(Wrappers.lambdaQuery(Project.class)
.in(Project::getId,projectIds)
.like(StringUtils.isNotBlank(req.getProjectName()),Project::getProjectName,req.getProjectName()));
Map<Long, Project> projectMap = CollUtils.listToMap(projects, Project::getId);
Map<Long, Contract> contractMap = projectIds.isEmpty() ? Maps.newHashMap()
: contractService.listByProjectIds(projectIds);
others = purchases.stream().filter(w -> projectMap.containsKey(w.getProjectId()))
.map(w -> {
XcfhxApplyListVO item = XcfhxApplyListVO.builder()
.bidId(w.getId())
.bizName(w.getBidName())
.status(w.getXcfhxApplyStatus())
.projectId(w.getProjectId())
.createOn(w.getCreateOn())
.sourceType(w.getSourceType())
.build();
Project project = projectMap.get(w.getProjectId());
item.setProjectCode(project.getProjectCode());
item.setProjectName(project.getProjectName());
item.setBuildOrgCode(project.getBuildOrgCode());
item.setBuildOrgName(project.getBuildOrgName());

Contract contract = contractMap.get(w.getId());
if (contract != null) {
item.setContractAmount(contract.getTotalAmount());
}
return item;
}).collect(Collectors.toList());
}
//合并
List<XcfhxApplyListVO> merge = Stream.of(manuals, others)
.flatMap(List::stream)
.filter(Objects::nonNull)
.collect(Collectors.toList());
return PageVo.of(merge.stream().sorted(Comparator.comparing(XcfhxApplyListVO::getCreateOn).reversed())
.skip((long) (pageNumber - 1) * pageSize)


+ 11
- 4
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/service/IPurchaseService.java View File

@@ -4,14 +4,18 @@ import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hz.pm.api.common.util.BizUtils;
import com.hz.pm.api.datascope.model.DataScopeDTO;
import com.hz.pm.api.datascope.utils.DataScopeUtil;
import com.hz.pm.api.projectdeclared.model.entity.Purchase;
import com.hz.pm.api.projectdeclared.model.req.XcfhxListReq;
import com.hz.pm.api.projectdeclared.model.vo.XcfhxApplyListVO;
import com.hz.pm.api.projectlib.model.enumeration.status.TenderStatus;
import com.hz.pm.api.user.security.model.UserFullInfoDTO;
import com.ningdatech.basic.util.CollUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

/**
@@ -49,4 +53,7 @@ public interface IPurchaseService extends IService<Purchase> {
return CollUtils.fieldSet(list(query), Purchase::getProjectId);
}

boolean buildPurchaseQueryPermission(LambdaQueryWrapper<Purchase> query, UserFullInfoDTO user);

List<XcfhxApplyListVO> listXcfhxApplyListVO(XcfhxListReq req);
}

+ 137
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/service/impl/PurchaseServiceImpl.java View File

@@ -1,11 +1,39 @@
package com.hz.pm.api.projectdeclared.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hz.pm.api.common.helper.UserInfoHelper;
import com.hz.pm.api.common.util.BizUtils;
import com.hz.pm.api.datascope.model.DataScopeDTO;
import com.hz.pm.api.datascope.utils.DataScopeUtil;
import com.hz.pm.api.projectdeclared.mapper.PurchaseMapper;
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.req.XcfhxListReq;
import com.hz.pm.api.projectdeclared.model.vo.XcfhxApplyListVO;
import com.hz.pm.api.projectdeclared.service.IContractService;
import com.hz.pm.api.projectdeclared.service.IPurchaseService;
import com.hz.pm.api.projectlib.model.entity.Project;
import com.hz.pm.api.projectlib.model.enumeration.status.TenderXcfhxApplyStatus;
import com.hz.pm.api.projectlib.service.IProjectService;
import com.hz.pm.api.user.helper.MhUnitCache;
import com.hz.pm.api.user.security.model.UserFullInfoDTO;
import com.hz.pm.api.user.util.LoginUserUtil;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.basic.util.CollUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
* <p>
* 服务实现类
@@ -15,7 +43,116 @@ import org.springframework.stereotype.Service;
* @since 2023-02-05
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
implements IPurchaseService {

private final UserInfoHelper userInfoHelper;

private final IProjectService projectService;

private final IContractService contractService;

private final MhUnitCache mhUnitCache;

@Override
public List<XcfhxApplyListVO> listXcfhxApplyListVO(XcfhxListReq req) {
LambdaQueryWrapper<Purchase> query = Wrappers.lambdaQuery(Purchase.class)
.like(StrUtil.isNotBlank(req.getBidName()), Purchase::getBidName, req.getBidName())
.le(req.getCreateOnMax() != null, Purchase::getCreateOn, req.getCreateOnMax())
.ge(req.getCreateOnMin() != null, Purchase::getCreateOn, req.getCreateOnMin())
.eq(req.getStatus() != null, Purchase::getXcfhxApplyStatus, req.getStatus())
.eq(req.getSourceType() != null,Purchase::getSourceType,req.getSourceType())
.ge(Objects.nonNull(req.getAmountStart()),Purchase::getTransactionAmount,req.getAmountStart())
.le(Objects.nonNull(req.getAmountEnd()),Purchase::getTransactionAmount,req.getAmountEnd())
.orderByDesc(Purchase::getCreateOn);

if (Boolean.TRUE.equals(req.getFinished())) {
query.eq(Purchase::getXcfhxApplyStatus, TenderXcfhxApplyStatus.XCFHX_APPLY_PASSED.getCode());
} else if (Boolean.FALSE.equals(req.getFinished())){
query.ne(Purchase::getXcfhxApplyStatus, TenderXcfhxApplyStatus.XCFHX_APPLY_PASSED.getCode());
}
UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
List<XcfhxApplyListVO> others = Lists.newArrayList();
if (!buildPurchaseQueryPermission(query, user)) {
return others;
}
List<Purchase> purchases = list(query);
if (CollUtil.isNotEmpty(purchases)) {
Set<Long> projectIds = CollUtils.fieldSet(purchases, Purchase::getProjectId);
List<Project> projects = projectIds.isEmpty() ? Lists.newArrayList() : projectService.list(Wrappers.lambdaQuery(Project.class)
.in(Project::getId,projectIds)
.like(StringUtils.isNotBlank(req.getProjectName()),Project::getProjectName,req.getProjectName()));
Map<Long, Project> projectMap = CollUtils.listToMap(projects, Project::getId);
Map<Long, Contract> contractMap = projectIds.isEmpty() ? Maps.newHashMap()
: contractService.listByProjectIds(projectIds);
others = purchases.stream().filter(w -> projectMap.containsKey(w.getProjectId()))
.map(w -> {
XcfhxApplyListVO item = XcfhxApplyListVO.builder()
.bidId(w.getId())
.bizName(w.getBidName())
.status(w.getXcfhxApplyStatus())
.projectId(w.getProjectId())
.createOn(w.getCreateOn())
.sourceType(w.getSourceType())
.build();
Project project = projectMap.get(w.getProjectId());
item.setProjectCode(project.getProjectCode());
item.setProjectName(project.getProjectName());
item.setBuildOrgCode(project.getBuildOrgCode());
item.setBuildOrgName(project.getBuildOrgName());

Contract contract = contractMap.get(w.getId());
if (contract != null) {
if(Objects.nonNull(req.getAmountStart()) && Objects.nonNull(contract.getTotalAmount())
&& req.getAmountStart().compareTo(contract.getTotalAmount()) > 0){
return null;
}
if(Objects.nonNull(req.getAmountEnd()) && Objects.nonNull(contract.getTotalAmount())
&& req.getAmountEnd().compareTo(contract.getTotalAmount()) < 0){
return null;
}
item.setContractAmount(contract.getTotalAmount());
}
return item;
}).collect(Collectors.toList());
}
return others;
}

public boolean buildPurchaseQueryPermission(LambdaQueryWrapper<Purchase> query, UserFullInfoDTO user) {
boolean queryState = true;
Optional<DataScopeDTO> datascope = DataScopeUtil.getCurrentUserDataScopeHasUserId(user);
if (!datascope.isPresent()) {
log.warn("没有取到权限信息 当前查询 没有权限条件");
queryState = false;
} else {
final String existsSql = "select 1 from nd_project np where np.id = nd_purchase.project_id and np.build_org_code";
switch (datascope.get().getRole()) {
case NORMAL_MEMBER:
//普通用户 只能看到自己单位去申报的
query.exists(String.format("%s = '%s'", existsSql, user.getMhUnitIdStr()));
break;
case COMPANY_MANAGER:
List<Long> childUnitIds = mhUnitCache.getViewChildIdsRecursion(user.getMhUnitId());
List<String> viewUnitIdList = CollUtils.convert(childUnitIds, String::valueOf);
query.exists(String.format("%s in %s", existsSql, BizUtils.inSqlJoin(viewUnitIdList)));
break;
case SUPER_ADMIN:
// 超级管理员 看到全市的 并且也要判断他 同时是不是单位管理员
break;
case VISITOR:
//访客可以看全市的
break;
case DASHBOARD:
break;
default:
//没有权限的话 就让它查不到
queryState = false;
break;
}
}
return queryState;
}
}

Loading…
Cancel
Save