|
|
|
|
@ -10,6 +10,7 @@ import org.dromara.common.core.enums.OAStatusEnum;
|
|
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
|
|
import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
|
|
import org.dromara.oa.erp.domain.ErpContractInfo;
|
|
|
|
|
import org.dromara.oa.erp.domain.ErpProjectInfo;
|
|
|
|
|
@ -53,6 +54,7 @@ import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
|
|
|
|
|
@ -78,7 +80,9 @@ public class ErpContractOrderServiceImpl implements IErpContractOrderService {
|
|
|
|
|
private final IErpProjectTypeService projectTypeService;
|
|
|
|
|
private final ICrmCustomerInfoService crmCustomerInfoService;
|
|
|
|
|
|
|
|
|
|
/** 项目申请流程编码(新增项目提交时使用) */
|
|
|
|
|
/**
|
|
|
|
|
* 项目申请流程编码(新增项目提交时使用)
|
|
|
|
|
*/
|
|
|
|
|
private static final String FLOW_CODE_PROJECT = "xmsq";
|
|
|
|
|
|
|
|
|
|
@DubboReference(timeout = 300000)
|
|
|
|
|
@ -117,6 +121,47 @@ public class ErpContractOrderServiceImpl implements IErpContractOrderService {
|
|
|
|
|
return TableDataInfo.build(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询合同订单待办列表(权限:项目经理或合同激活创建人)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<ErpProjectInfoVo> queryTodoList(ErpProjectInfoBo bo) {
|
|
|
|
|
// 先取基础列表,再按“真实项目经理 / 合同创建人”在内存中过滤
|
|
|
|
|
Long filterManagerId = bo.getManagerId();
|
|
|
|
|
bo.setManagerId(null);
|
|
|
|
|
MPJLambdaWrapper<ErpProjectInfo> lqw = buildQueryWrapper(bo);
|
|
|
|
|
List<ErpProjectInfoVo> baseList = projectInfoMapper.selectCustomErpProjectInfoVoList(lqw);
|
|
|
|
|
if (CollUtil.isEmpty(baseList)) {
|
|
|
|
|
return baseList;
|
|
|
|
|
}
|
|
|
|
|
Long currentUserId = LoginHelper.getUserId();
|
|
|
|
|
if (StringUtils.isNull(filterManagerId)) {
|
|
|
|
|
return baseList;
|
|
|
|
|
}
|
|
|
|
|
// 1) 批量取合同ID
|
|
|
|
|
Set<Long> contractIds = baseList.stream()
|
|
|
|
|
.map(ErpProjectInfoVo::getContractId)
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
// 2) 合同ID -> 项目经理ID(通过 erp_project_contracts -> erp_project_info)
|
|
|
|
|
Map<Long, Long> contractId2ManagerId = buildContractIdToProjectManagerIdMap(contractIds);
|
|
|
|
|
// 3) 合同ID -> 合同创建人
|
|
|
|
|
Map<Long, Long> contractId2CreateBy = buildContractIdToContractCreateByMap(contractIds);
|
|
|
|
|
return baseList.stream()
|
|
|
|
|
.filter(row -> {
|
|
|
|
|
Long contractId = row.getContractId();
|
|
|
|
|
Long realManagerId = contractId != null ? contractId2ManagerId.get(contractId) : null;
|
|
|
|
|
Long contractCreateBy = contractId != null ? contractId2CreateBy.get(contractId) : null;
|
|
|
|
|
// 过滤条件:页面选择的项目经理(按真实项目经理)
|
|
|
|
|
if (filterManagerId != null) {
|
|
|
|
|
return Objects.equals(filterManagerId, realManagerId);
|
|
|
|
|
}
|
|
|
|
|
// 待办权限:真实项目经理 或 合同激活创建人
|
|
|
|
|
return Objects.equals(currentUserId, realManagerId) || Objects.equals(currentUserId, contractCreateBy);
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询符合条件的合同订单列表
|
|
|
|
|
*
|
|
|
|
|
@ -167,6 +212,62 @@ public class ErpContractOrderServiceImpl implements IErpContractOrderService {
|
|
|
|
|
return lqw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<Long, Long> buildContractIdToProjectManagerIdMap(Set<Long> contractIds) {
|
|
|
|
|
if (CollUtil.isEmpty(contractIds)) {
|
|
|
|
|
return MapUtil.empty();
|
|
|
|
|
}
|
|
|
|
|
// contract_id -> project_id(若一合同关联多个项目,这里取第一条;如需更严格可调整为一对多)
|
|
|
|
|
List<ErpProjectContracts> pcs = projectContractsMapper.selectList(new LambdaQueryWrapper<ErpProjectContracts>()
|
|
|
|
|
.in(ErpProjectContracts::getContractId, contractIds)
|
|
|
|
|
.eq(ErpProjectContracts::getDelFlag, "0")
|
|
|
|
|
.orderByAsc(ErpProjectContracts::getSortOrder)
|
|
|
|
|
.orderByAsc(ErpProjectContracts::getProjectContractsId));
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(pcs)) {
|
|
|
|
|
return MapUtil.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<Long, Long> contractId2ProjectId = pcs.stream()
|
|
|
|
|
.filter(x -> x.getContractId() != null && x.getProjectId() != null)
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
ErpProjectContracts::getContractId,
|
|
|
|
|
ErpProjectContracts::getProjectId,
|
|
|
|
|
(a, b) -> a
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
Set<Long> projectIds = contractId2ProjectId.values().stream().filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
|
|
if (CollUtil.isEmpty(projectIds)) {
|
|
|
|
|
return MapUtil.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<ErpProjectInfo> projects = projectInfoMapper.selectList(new LambdaQueryWrapper<ErpProjectInfo>()
|
|
|
|
|
.select(ErpProjectInfo::getProjectId, ErpProjectInfo::getManagerId)
|
|
|
|
|
.in(ErpProjectInfo::getProjectId, projectIds)
|
|
|
|
|
.eq(ErpProjectInfo::getDelFlag, "0"));
|
|
|
|
|
|
|
|
|
|
Map<Long, Long> projectId2ManagerId = projects.stream()
|
|
|
|
|
.filter(p -> p.getProjectId() != null)
|
|
|
|
|
.collect(Collectors.toMap(ErpProjectInfo::getProjectId, ErpProjectInfo::getManagerId, (a, b) -> a));
|
|
|
|
|
|
|
|
|
|
return contractId2ProjectId.entrySet().stream()
|
|
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, e -> projectId2ManagerId.get(e.getValue()), (a, b) -> a));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<Long, Long> buildContractIdToContractCreateByMap(Set<Long> contractIds) {
|
|
|
|
|
if (CollUtil.isEmpty(contractIds)) {
|
|
|
|
|
return MapUtil.empty();
|
|
|
|
|
}
|
|
|
|
|
List<ErpContractInfo> contracts = contractInfoMapper.selectList(new LambdaQueryWrapper<ErpContractInfo>()
|
|
|
|
|
.select(ErpContractInfo::getContractId, ErpContractInfo::getCreateBy)
|
|
|
|
|
.in(ErpContractInfo::getContractId, contractIds));
|
|
|
|
|
if (CollUtil.isEmpty(contracts)) {
|
|
|
|
|
return MapUtil.empty();
|
|
|
|
|
}
|
|
|
|
|
return contracts.stream()
|
|
|
|
|
.filter(c -> c.getContractId() != null)
|
|
|
|
|
.collect(Collectors.toMap(ErpContractInfo::getContractId, ErpContractInfo::getCreateBy, (a, b) -> a));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 暂存合同订单(项目信息)
|
|
|
|
|
*
|
|
|
|
|
|