- 添加auditLog空值检查避免NullReferenceException - 为开户审批和其他审批流程分别处理不同的流程列表 - 添加错误日志记录以便调试auditLog为空的情况 - 当auditLog为空时按一般审批流程处理以确保功能正常运行
1945 lines
98 KiB
C#
1945 lines
98 KiB
C#
using Autofac.Features.Indexed;
|
|
using Autofac.Features.OwnedInstances;
|
|
using BaseOUDAL;
|
|
using ClosedXML;
|
|
using DocumentFormat.OpenXml.Math;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using iTextSharp.text.pdf.codec.wmf;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
|
using Qdp.Foundation.Utilities;
|
|
using System;
|
|
using System.Linq.Expressions;
|
|
using YLErp.BLL;
|
|
using YLErp.BLL.Eod;
|
|
using YLErp.BLL.EodSettlement;
|
|
using YLErp.DBModels;
|
|
using YLErp.Helpers;
|
|
using YLErp.Model;
|
|
using YLErp.Model.Enum;
|
|
using YLErp.Models;
|
|
using YLErp.Modules.BasicDataModule;
|
|
using YLErp.Modules.ClientModule.Dto;
|
|
using YLErp.Modules.SystemModule;
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
|
|
namespace YLErp.Modules.ClientModule
|
|
{
|
|
/// <summary>
|
|
/// 客户查询服务基类
|
|
/// </summary>
|
|
public class ClientQueryService : ClientBaseService
|
|
{
|
|
public ClientQueryService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询client不分页
|
|
/// </summary>
|
|
public List<ClientLinq> SearchListClient(ClientReq req)
|
|
{
|
|
//系统交易日
|
|
var valueDate = valuedateBLL.ValueDate;
|
|
if (!req.ValueDate.HasValue)
|
|
{
|
|
req.ValueDate = valueDate;
|
|
}
|
|
var clientPredicate = CreatePredicate(req);
|
|
var clientRatingQuery = DbContext.Client_Rating.Where(x => !x.IsDeleted && x.ProcessStatus == "已审批" && x.RatingStartDate <= valueDate && x.RatingDeadLine >= valueDate);
|
|
var query = from source in DbContext.client
|
|
join clientRating in clientRatingQuery on source.id equals clientRating.ClientId into clientR
|
|
from crating in clientR.DefaultIfEmpty()
|
|
join creditRating in DbContext.credit_rating.Where(a => a.ValidState == "Valid") on crating.CreditRatingId equals creditRating.id into creditR
|
|
from rating in creditR.DefaultIfEmpty()
|
|
join cl in DbContext.clientlevel on source.LevelId equals cl.id into clientL
|
|
from clientlevel in clientL.DefaultIfEmpty()
|
|
select new ClientLinq
|
|
{
|
|
id = source.id,
|
|
Number = source.Number,
|
|
Name = source.Name,
|
|
Level = clientlevel == null ? "" : clientlevel.LevelName,
|
|
CreditDirection = source.CreditDirection,
|
|
CreditYear = source.CreditYear,
|
|
CreditDeadline = source.CreditDeadline,
|
|
CreditTemp = source.CreditTemp,
|
|
CreditTempDeadline = source.CreditTempDeadline,
|
|
OptId = source.OptId,
|
|
OptName = source.OptName,
|
|
OptDate = source.OptDate,
|
|
Type = source.Type,
|
|
IdentificationNumber = source.IdentificationNumber,
|
|
Phone = source.Phone,
|
|
Address = source.Address,
|
|
Email = source.Email,
|
|
LevelId = source.LevelId,
|
|
Capitalbalance = source.Capitalbalance,
|
|
PendingMarginCallPayment = source.PendingMarginCallPayment,
|
|
Seller = source.Seller,
|
|
CustomerManager = source.CustomerManager,
|
|
CustomerManagerId = source.CustomerManagerId,
|
|
SalesDepartmentId = source.SalesDepartmentId,
|
|
ProcessStatus = source.ProcessStatus,
|
|
ProcessOptDate = source.ProcessOptDate,
|
|
EvaluateOfValidity = source.EvaluateOfValidity,
|
|
EvaluateDate = source.EvaluateDate,
|
|
CreditRatingId = rating == null ? 0 : rating.id,
|
|
CreditRatingName = rating == null ? "" : rating.CreditName,
|
|
//CreditLine = (credit == null ? 0 : credit.Credit) > 0 ? (credit == null ? 0 : credit.Credit) : 0,
|
|
AppropriatenessDegree = source.AppropriatenessDegree,
|
|
RiskServiceDegree = source.RiskServiceDegree,
|
|
ProtocolSignDate = source.ProtocolSignDate,
|
|
ProperClientClass = source.ProperClientClass,
|
|
CustomerNature = source.CustomerNature,
|
|
CustomerNature1 = source.CustomerNature1,
|
|
CustomerNature2 = source.CustomerNature2,
|
|
Guid = source.Guid,
|
|
PostalAddress = source.PostalAddress,
|
|
PostalCode = source.PostalCode,
|
|
LicenseCode = source.LicenseCode,
|
|
RegisteredCapital = source.RegisteredCapital,
|
|
ActualBeneficiary = source.ActualBeneficiary,
|
|
ActualController = source.ActualController,
|
|
RegisteredAddress = source.RegisteredAddress,
|
|
FinancialSituation = source.FinancialSituation,
|
|
InvestmentExperience = source.InvestmentExperience,
|
|
IsIndustryConnectVariety = source.IsIndustryConnectVariety,
|
|
TransactionTarget = source.TransactionTarget,
|
|
InvestmentTerm = source.InvestmentTerm,
|
|
IsRealControl = source.IsRealControl,
|
|
DerivativesInvestmentVarieties = source.DerivativesInvestmentVarieties,
|
|
FundsSource = source.FundsSource,
|
|
AcceptableLoss = source.AcceptableLoss,
|
|
RiskPreference = source.RiskPreference,
|
|
BadFaithRecord = source.BadFaithRecord,
|
|
IsEvaluate = source.IsEvaluate,
|
|
QuestionnaireScore = source.QuestionnaireScore,
|
|
IsAcceptHighRiskService = source.IsAcceptHighRiskService,
|
|
AppropriatenessAssessor = source.AppropriatenessAssessor,
|
|
IsRequireConversionTypes = source.IsRequireConversionTypes,
|
|
IsAssessmentResultChange = source.IsAssessmentResultChange,
|
|
Remark = source.Remark,
|
|
ChangeReasonAndEvaluationResults = source.ChangeReasonAndEvaluationResults,
|
|
DisbeliefRecord = source.DisbeliefRecord,
|
|
LicenseType = source.LicenseType,
|
|
ClientType = source.ClientType,
|
|
BusinessType = source.BusinessType,
|
|
InstitutionalAttributes = source.InstitutionalAttributes,
|
|
Region = source.Region,
|
|
BoundSide = source.BoundSide,
|
|
SettlementCurrency = source.SettlementCurrency,
|
|
IsTradeCredit = source.IsTradeCredit,
|
|
IsCreditOn = source.IsCreditOn,
|
|
AgreementBookNo = source.AgreementBookNo,
|
|
AgreementBookType = source.AgreementBookType,
|
|
Seat = source.Seat
|
|
};
|
|
|
|
query = query.OrderByDescending(q => q.id);
|
|
|
|
var retListResult = query.ToList();
|
|
|
|
var clientIds = retListResult.Select(n => n.id).ToArray();
|
|
var creditQuery = from c in yldb.credit
|
|
where clientIds.Contains(c.ClientId.Value) && c.ProcessStatus == "已审批"
|
|
&& (c.CreditStartDate == null || c.CreditStartDate <= req.ValueDate)
|
|
&& (c.CreditDeadLine == null || c.CreditDeadLine >= req.ValueDate)
|
|
select new { ClientId = c.ClientId.Value, c.Credit };
|
|
var creditDic = creditQuery.ToDictionary(n => n.ClientId, m => m.Credit);
|
|
|
|
foreach (var clientLinq in retListResult)
|
|
{
|
|
if (creditDic.TryGetValue(clientLinq.id, out var credit) && credit.HasValue)
|
|
{
|
|
clientLinq.CreditLine = credit;
|
|
}
|
|
new ClientLinqExtendService(this, clientLinq).ExtendEnumName().ExtendEvaluateDate().ExtendClientDuty();
|
|
}
|
|
|
|
return retListResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询client
|
|
/// </summary>
|
|
public SearchListResult<ClientLinq> SearchList(ClientReq req, Expression<Func<Client, bool>> clientPredicate = null)
|
|
{
|
|
var clientProcessList = yldb.approvalprocess.Where(x => x.processType == "ClientProcess").ToArray();
|
|
var openProcessList = yldb.approvalprocess.Where(x => x.processType == "OpenProcess").ToArray();
|
|
|
|
if (!req.ValueDate.HasValue)
|
|
{
|
|
req.ValueDate = valuedateBLL.ValueDate;
|
|
}
|
|
|
|
if (clientPredicate == null)
|
|
{
|
|
clientPredicate = CreatePredicate(req);
|
|
}
|
|
|
|
if (!(req.ApprovalStatus == "全部" || string.IsNullOrEmpty(req.ApprovalStatus)))
|
|
{
|
|
clientPredicate = clientPredicate.And(d => req.ApprovalStatusList.Contains(d.ApprovalStatus));
|
|
}
|
|
|
|
//SetDebugSqlLog();
|
|
var query = from source in DbContext.client.Where(clientPredicate)
|
|
join cl in DbContext.clientlevel on source.LevelId equals cl.id into clientL
|
|
from clientlevel in clientL.DefaultIfEmpty()
|
|
join ca in DbContext.ClientAuditLog on source.ApprovalLogId equals ca.id into calog
|
|
from ca in calog.DefaultIfEmpty()
|
|
select new ClientLinq
|
|
{
|
|
id = source.id,
|
|
Number = source.Number,
|
|
Name = source.Name,
|
|
Level = clientlevel == null ? "" : clientlevel.LevelName,
|
|
CreditDirection = source.CreditDirection,
|
|
CreditYear = source.CreditYear,
|
|
CreditDeadline = source.CreditDeadline,
|
|
CreditTemp = source.CreditTemp,
|
|
CreditTempDeadline = source.CreditTempDeadline,
|
|
CreatorId = source.CreatorId,
|
|
CreatorName = source.CreatorName,
|
|
CreateDate = source.CreateDate,
|
|
OptId = source.OptId,
|
|
OptName = source.OptName,
|
|
OptDate = source.OptDate,
|
|
Type = source.Type,
|
|
IdentificationNumber = source.IdentificationNumber,
|
|
Phone = source.Phone,
|
|
Address = source.Address,
|
|
Email = source.Email,
|
|
LevelId = source.LevelId,
|
|
Capitalbalance = source.Capitalbalance,
|
|
PendingMarginCallPayment = source.PendingMarginCallPayment,
|
|
Seller = source.Seller,
|
|
CustomerManager = source.CustomerManager,
|
|
CustomerManagerId = source.CustomerManagerId,
|
|
SalesDepartmentId = source.SalesDepartmentId,
|
|
ProcessStatus = source.ProcessStatus,
|
|
ProcessOptDate = source.ProcessOptDate,
|
|
ProcessOrderId = source.ProcessOrderId,
|
|
ProcessOrderBranch = source.ProcessOrderBranch,
|
|
ApprovalStatus = source.ApprovalStatus,
|
|
ApprovalOrderId = source.ApprovalOrderId,
|
|
EvaluateOfValidity = source.EvaluateOfValidity,
|
|
EvaluateDate = source.EvaluateDate,
|
|
EvaluateExpireDate = source.EvaluateExpireDate,
|
|
AppropriatenessDegree = source.AppropriatenessDegree,
|
|
RiskServiceDegree = source.RiskServiceDegree,
|
|
ProtocolSignDate = source.ProtocolSignDate,
|
|
RightProtocolSignDate = source.RightProtocolSignDate,
|
|
ProtocolSignVersion = source.ProtocolSignVersion,
|
|
ProperClientClass = source.ProperClientClass,
|
|
CustomerNature = source.CustomerNature,
|
|
CustomerNature1 = source.CustomerNature1,
|
|
CustomerNature2 = source.CustomerNature2,
|
|
Guid = source.Guid,
|
|
PostalAddress = source.PostalAddress,
|
|
PostalCode = source.PostalCode,
|
|
LicenseCode = source.LicenseCode,
|
|
RegisteredCapital = source.RegisteredCapital,
|
|
ActualBeneficiary = source.ActualBeneficiary,
|
|
ActualController = source.ActualController,
|
|
RegisteredAddress = source.RegisteredAddress,
|
|
FinancialSituation = source.FinancialSituation,
|
|
InvestmentExperience = source.InvestmentExperience,
|
|
IsIndustryConnectVariety = source.IsIndustryConnectVariety,
|
|
TransactionTarget = source.TransactionTarget,
|
|
InvestmentTerm = source.InvestmentTerm,
|
|
IsRealControl = source.IsRealControl,
|
|
//中粮是否小微企业
|
|
IsSmallAndMicroEnterprises = source.IsSmallAndMicroEnterprises,
|
|
DerivativesInvestmentVarieties = source.DerivativesInvestmentVarieties,
|
|
FundsSource = source.FundsSource,
|
|
AcceptableLoss = source.AcceptableLoss,
|
|
RiskPreference = source.RiskPreference,
|
|
ExpectedReturn2 = source.ExpectedReturn2,
|
|
BadFaithRecord = source.BadFaithRecord,
|
|
IsEvaluate = source.IsEvaluate,
|
|
QuestionnaireScore = source.QuestionnaireScore,
|
|
IsAcceptHighRiskService = source.IsAcceptHighRiskService,
|
|
AppropriatenessAssessor = source.AppropriatenessAssessor,
|
|
IsRequireConversionTypes = source.IsRequireConversionTypes,
|
|
IsAssessmentResultChange = source.IsAssessmentResultChange,
|
|
Remark = source.Remark,
|
|
ChangeReasonAndEvaluationResults = source.ChangeReasonAndEvaluationResults,
|
|
DisbeliefRecord = source.DisbeliefRecord,
|
|
LicenseType = source.LicenseType,
|
|
ClientType = source.ClientType,
|
|
ProductNumber = source.ProductNumber,
|
|
BusinessType = source.BusinessType,
|
|
InstitutionalAttributes = source.InstitutionalAttributes,
|
|
Region = source.Region,
|
|
IsTradeCredit = source.IsTradeCredit,
|
|
IsCreditOn = source.IsCreditOn,
|
|
SamePeer = source.SamePeer,
|
|
AdminFullName = source.AdminFullName,
|
|
AdminRegisteredNum = source.AdminRegisteredNum,
|
|
NFICode = source.NFICode,
|
|
CounterpartyCode = source.CounterpartyCode,
|
|
ParentId = source.ParentId,
|
|
BoundSide = source.BoundSide,
|
|
SettlementCurrency = source.SettlementCurrency,
|
|
IsDocShowParentName = source.IsDocShowParentName,
|
|
AgreementBookNo = source.AgreementBookNo,
|
|
AgreementBookType = source.AgreementBookType,
|
|
Seat = source.Seat,
|
|
MainProtocolCode = source.MainProtocolCode,
|
|
SupProtocolCode = source.SupProtocolCode,
|
|
Abbreviation = source.Abbreviation,
|
|
ClearingAgency = source.ClearingAgency,
|
|
MarginOptionType = source.MarginOptionType,
|
|
ConfirmBookMode = source.ConfirmBookMode,
|
|
SupProtocolDate = source.SupProtocolDate,
|
|
IsInsided = source.IsInsided,
|
|
IsSendRecovery = source.IsSendRecovery,
|
|
IsCentralClearing = source.IsCentralClearing,
|
|
CentralClearingPaltform = source.CentralClearingPaltform,
|
|
TradingPaltform = source.TradingPaltform,
|
|
LEICode = source.LEICode,
|
|
IsListed = source.IsListed,
|
|
Department = source.Department,
|
|
ServiceType = source.ServiceType,
|
|
TradingInstType = source.TradingInstType,
|
|
TradingInstTypeName = DBModels.Enums.TradingInstTypeUtil.GetDesc(source.TradingInstType),
|
|
LicenseValidTimeStr = source.LicenseValidTimeStr == "30001231" ? "长期有效" : source.LicenseValidTime.Value.ToString("yyyy-MM-dd"),
|
|
auditLog = ca,
|
|
ClientRight =source.ClientRight,
|
|
ProxyEmail = source.ProxyEmail,
|
|
SwapTradeType = source.SwapTradeType,
|
|
UnifiedSocialCreditCode = source.UnifiedSocialCreditCode,
|
|
SettleFileNumber = source.SettleFileNumber,
|
|
OutNumber=source.OutNumber,
|
|
Manager=source.Manager,
|
|
BusinessUseType= source.BusinessUseType,
|
|
ManagerAbbreviation= source.ManagerAbbreviation,
|
|
ManagerSocialCreditCode= source.ManagerSocialCreditCode,
|
|
};
|
|
|
|
var lastSettlementDate = EodOperationBase.GetLastSettlementDate(DateTime.Now.Date);
|
|
var cashinCashoutSumQuery = from c in yldb.ClientCashInCashOut
|
|
where c.Comments == "信用风险亏损" && c.HappenDate == req.ValueDate
|
|
&& (c.State == "已确认" || c.State == "已结算")
|
|
group c by c.ClientId into g
|
|
select new
|
|
{
|
|
ClientId = g.Key,
|
|
CashSum = g.Sum(n => n.Money)
|
|
};
|
|
var cashinCashoutSumQueryDic = cashinCashoutSumQuery.ToDictionary(n => n.ClientId);
|
|
if (string.IsNullOrEmpty(req.sidx))
|
|
{
|
|
req.sidx = "Number";
|
|
req.sord = "desc";
|
|
}
|
|
|
|
if (req.AssessmentExpiredStatus > 0)
|
|
{
|
|
var deadline = DateTime.Now.Date.AddDays(req.AssessmentExpiredStatus);
|
|
if (req.AssessmentExpiredStatus == 1)
|
|
{
|
|
query = query.Where(t => t.EvaluateExpireDate <= deadline);
|
|
}
|
|
else
|
|
{
|
|
var deadlineStart = DateTime.Now.Date.AddDays(1);
|
|
query = query.Where(t => t.EvaluateExpireDate >= deadlineStart && t.EvaluateExpireDate <= deadline);
|
|
}
|
|
}
|
|
|
|
var retListResult = query.ToSearchList(req);
|
|
if (retListResult == null || retListResult.rows == null || !retListResult.rows.Any())
|
|
{
|
|
return retListResult;
|
|
}
|
|
|
|
var clientIds = retListResult.rows.Select(p => p.id).Distinct().ToList();
|
|
|
|
var appropriatenessAssessorList = ClientDataModelV1.GetAppropriatenessAssessor(false);
|
|
|
|
var parentClientIds = retListResult.rows.Where(p => p.ParentId > 0).Select(p => p.ParentId).Distinct().ToList();
|
|
List<Client> parentClientList = null;
|
|
if (parentClientIds != null && parentClientIds.Any())
|
|
{
|
|
parentClientList = DbContext.client.Where(p => parentClientIds.Contains(p.id)).AsNoTracking().ToList();
|
|
}
|
|
if (parentClientList == null)
|
|
{
|
|
parentClientList = new List<Client>();
|
|
}
|
|
List<ClientMeta> clientMetaList = DbContext.ClientMeta.Where(p => clientIds.Contains(p.ClientId)).AsNoTracking().ToList();
|
|
if (clientMetaList == null)
|
|
{
|
|
clientMetaList = new List<ClientMeta>();
|
|
}
|
|
|
|
var yldic = DictionaryBLL.GetDictionary("适当性客户分类");
|
|
|
|
List<ClientDuty> clientDutyList = DbContext.clientduty.Where(p => p.ApprovalOrder < 1 && clientIds.Contains((int)p.ClientId)).AsNoTracking().ToList();
|
|
if (clientDutyList == null)
|
|
{
|
|
clientDutyList = new List<ClientDuty>();
|
|
}
|
|
|
|
List<ClientRating> clientRatingList = DbContext.Client_Rating.Where(p => clientIds.Contains(p.ClientId) && !p.IsDeleted && p.RatingStartDate <= req.ValueDate.Value && p.RatingDeadLine >= req.ValueDate.Value && p.ProcessStatus == "已审批").AsNoTracking().ToList();
|
|
if (clientRatingList == null)
|
|
{
|
|
clientRatingList = new List<ClientRating>();
|
|
}
|
|
|
|
Dictionary<int, double> realtime_Trade_RiskList = null;
|
|
Dictionary<int, double> eod_Trade_RiskList = null;
|
|
if (lastSettlementDate < req.ValueDate.Value)
|
|
{
|
|
var gQuery = from p in yldb.realtime_trade_risk
|
|
where clientIds.Contains((int)p.ClientId) && "持仓".Equals(p.VolType)
|
|
group p by p.ClientId.Value into g
|
|
select new { g.Key, sum = g.Sum(n => n.CreditExposure) };
|
|
|
|
realtime_Trade_RiskList = gQuery.ToDictionary(t => t.Key, t => t.sum);
|
|
}
|
|
else
|
|
{
|
|
eod_Trade_RiskList = yldb.eod_trade_risk.Where(p => clientIds.Contains(p.ClientId) && p.ValueDate == req.ValueDate.Value).AsEnumerable().GroupBy(p => (int)p.ClientId).ToDictionary(t => t.Key, t => t.Sum(d => d.CreditExposure));
|
|
}
|
|
if (realtime_Trade_RiskList == null)
|
|
{
|
|
realtime_Trade_RiskList = new Dictionary<int, double>();
|
|
}
|
|
if (eod_Trade_RiskList == null)
|
|
{
|
|
eod_Trade_RiskList = new Dictionary<int, double>();
|
|
}
|
|
var roles = ApprovalGradeDataService.getAllRoles();
|
|
|
|
foreach (var clientLinq in retListResult.rows)
|
|
{
|
|
if (PS.Config.IsGuoJun)
|
|
{
|
|
clientLinq.ConfirmBookMode = clientLinq.SupProtocolDate != null ? "单章版" : "双章版";
|
|
}
|
|
if (lastSettlementDate < req.ValueDate.Value)
|
|
{
|
|
if (realtime_Trade_RiskList.ContainsKey(clientLinq.id))
|
|
{
|
|
clientLinq.Exposure = realtime_Trade_RiskList[clientLinq.id];
|
|
}
|
|
//clientLinq.Exposure = realtime_Trade_RiskList.Where(o => o.ClientId == clientLinq.id && o.VolType == "持仓").Sum(o => (double?)o.CreditExposure) ?? 0;
|
|
}
|
|
else
|
|
{
|
|
if (eod_Trade_RiskList.ContainsKey(clientLinq.id))
|
|
{
|
|
clientLinq.Exposure = eod_Trade_RiskList[clientLinq.id];
|
|
}
|
|
//clientLinq.Exposure = eod_Trade_RiskList.Where(o => o.ClientId == clientLinq.id && o.ValueDate == req.ValueDate.Value).Sum(o => (double?)o.CreditExposure) ?? 0;
|
|
}
|
|
if (cashinCashoutSumQueryDic.TryGetValue(clientLinq.id, out var dicItem1))
|
|
{
|
|
clientLinq.CreditRiskLoss = dicItem1.CashSum ?? 0;
|
|
}
|
|
if (PS.Config.Company == Configuration.CompanyEnum.中金)
|
|
{
|
|
//clientLinq.ProductName = new ClientQueryService(OptUser).GetProductName(clientLinq.id);
|
|
var clientMeta = clientMetaList.FirstOrDefault(o => o.ClientId == clientLinq.id && o.MetaKey == "产品名称");
|
|
clientLinq.ProductName = clientMeta?.MetaValue;
|
|
}
|
|
new ClientLinqExtendService(this, clientLinq, req.CheckContactExpired).ExtendAll(req.ValueDate.Value, appropriatenessAssessorList, parentClientList, yldic, clientDutyList, clientRatingList, clientMetaList);
|
|
clientLinq.ProcessRoleId = GetApprovalRoleId(clientProcessList.ToList(), clientLinq.ApprovalOrderId, clientLinq.ProcessOrderBranch);
|
|
clientLinq.ApprovalRole = roles.Where(x => x.Id == clientLinq.ProcessRoleId)?.FirstOrDefault()?.Name;
|
|
if (clientLinq.ApprovalStatus == "审批中")
|
|
{
|
|
// 添加空值检查并记录日志
|
|
if (clientLinq.auditLog != null)
|
|
{
|
|
if (clientLinq.auditLog.OptType.Contains("开户审批"))
|
|
{
|
|
clientLinq.ApprovalStatus = GetApprovalStatus(openProcessList.ToList(), clientLinq.ApprovalStatus, clientLinq.ApprovalOrderId, clientLinq.ProcessOrderBranch);
|
|
}
|
|
else
|
|
{
|
|
clientLinq.ApprovalStatus = GetApprovalStatus(clientProcessList.ToList(), clientLinq.ApprovalStatus, clientLinq.ApprovalOrderId, clientLinq.ProcessOrderBranch);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 记录auditLog为空的情况,便于后续调试
|
|
LogFactory.GetLogger("ClientQueryService").Error("ClientQueryService.SearchList: auditLog is null for client id: " + clientLinq.id + ", ApprovalOrderId: " + clientLinq.ApprovalOrderId + ", ProcessOrderBranch: " + clientLinq.ProcessOrderBranch + ", ApprovalStatus: " + clientLinq.ApprovalStatus);
|
|
// 当auditLog为空时,无法判断是否为开户审批,按一般审批流程处理
|
|
clientLinq.ApprovalStatus = GetApprovalStatus(clientProcessList.ToList(), clientLinq.ApprovalStatus, clientLinq.ApprovalOrderId, clientLinq.ProcessOrderBranch);
|
|
}
|
|
}
|
|
}
|
|
|
|
return retListResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询client
|
|
/// </summary>
|
|
public SearchListResult<ClientLinq> SearchClientPnlInfoList(ClientReq req, Expression<Func<Client, bool>> clientPredicate = null)
|
|
{
|
|
if (!req.ValueDate.HasValue)
|
|
{
|
|
req.ValueDate = valuedateBLL.ValueDate;
|
|
}
|
|
|
|
if (clientPredicate == null)
|
|
{
|
|
clientPredicate = CreatePredicate(req);
|
|
}
|
|
var query = from source in DbContext.client.Where(clientPredicate)
|
|
select new ClientLinq
|
|
{
|
|
id = source.id,
|
|
Number = source.Number,
|
|
Name = source.Name,
|
|
CustomerManager = source.CustomerManager,
|
|
CustomerManagerId = source.CustomerManagerId,
|
|
CustomerNature = source.CustomerNature,
|
|
CustomerNature1 = source.CustomerNature1,
|
|
CustomerNature2 = source.CustomerNature2,
|
|
};
|
|
|
|
var PrewhereModeClientIds = new List<int>();
|
|
|
|
if (req.HaveTrade || req.HavePosition || req.HaveBanlance)
|
|
{
|
|
if (req.HaveTrade)
|
|
{
|
|
var hasTradeQuery = from tCash in yldb.trade_cash
|
|
join t in yldb.trade on tCash.TradeId equals t.id
|
|
where t.ValidState != "InValid" && t.TradeType != "收益互换" && (t.TradeType != "结构化交易" || t.IsGroup == 1) && t.IsGroup != 2
|
|
&& tCash.ValidState != "InValid" && tCash.ValueDate >= req.StartDate && tCash.ValueDate <= req.ValueDate && (tCash.Action != "系统操作-票息" || tCash.IsLastAction)
|
|
select t.ClientId;
|
|
|
|
PrewhereModeClientIds.AddRange(hasTradeQuery.ToList());
|
|
}
|
|
if (req.HavePosition)
|
|
{
|
|
PrewhereModeClientIds.AddRange(yldb.eod_trade_position.AsNoTracking().Where(n => n.ValueDate >= req.StartDate && n.ValueDate <= req.ValueDate && n.ClientId > 0 && n.TradeId > 0 && n.Amount > 0).Select(n => n.ClientId).ToList());
|
|
}
|
|
if (req.HaveBanlance)
|
|
{
|
|
var endDate = req.ValueDate.Value.AddDays(1);
|
|
PrewhereModeClientIds.AddRange(yldb.ClientCashInCashOut.AsNoTracking().Where(n => n.HappenDate >= req.StartDate && n.HappenDate < endDate && n.ClientId > 0 && n.ValidState != "InValid").Select(n => n.ClientId.Value).ToList());
|
|
}
|
|
PrewhereModeClientIds = PrewhereModeClientIds.Distinct().ToList();
|
|
query = query.Where(n => PrewhereModeClientIds.Contains(n.id));
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(req.sidx))
|
|
{
|
|
req.sidx = "Number";
|
|
req.sord = "desc";
|
|
}
|
|
var retListResult = query.ToSearchList(req);
|
|
|
|
foreach (var clientLinq in retListResult.rows)
|
|
{
|
|
new ClientLinqExtendService(this, clientLinq, req.CheckContactExpired).ExtendEnumName();
|
|
}
|
|
return retListResult;
|
|
}
|
|
|
|
public SearchListResult<ClientLinq> SearchOpeningProcessList(ClientReq req, bool filterAudit = false)
|
|
{
|
|
var openProcessList = yldb.approvalprocess.Where(x => x.processType == "OpenProcess").ToArray();
|
|
|
|
//系统交易日
|
|
var valueDate = valuedateBLL.ValueDate;
|
|
if (!req.ValueDate.HasValue)
|
|
{
|
|
req.ValueDate = valueDate;
|
|
}
|
|
var clientPredicate = CreatePredicate(req, true);
|
|
if (filterAudit)
|
|
{
|
|
var groupId = UserBLL.GetApprovalProcessGroup(UserId);
|
|
var approvalConditionFirst = openProcessList.FirstOrDefault(x => x.approvalGroupId == groupId && x.approvalCondition == 1);//属于某个审批组
|
|
var approvalConditionSecend = openProcessList.FirstOrDefault(x => x.approvalGroupId != groupId && x.approvalCondition == 2);//不属于某个审批组
|
|
var nodeArr = new List<int?> { 0 };
|
|
if (approvalConditionFirst != null)
|
|
{
|
|
nodeArr.Add(approvalConditionFirst.node);
|
|
}
|
|
if (approvalConditionSecend != null)
|
|
{
|
|
nodeArr.Add(approvalConditionSecend.node);
|
|
}
|
|
clientPredicate = clientPredicate.And(d => nodeArr.Contains(d.ProcessOrderBranch));
|
|
}
|
|
else
|
|
{
|
|
if (req.ProcessStatus == "全部" || string.IsNullOrEmpty(req.ProcessStatus))
|
|
{
|
|
clientPredicate = clientPredicate.And(s => s.ProcessStatus != "已开户" && s.ProcessStatus != "已销户" && s.ProcessStatus != "已休眠");
|
|
}
|
|
else
|
|
{
|
|
clientPredicate = clientPredicate.And(d => req.ProcessStatusList.Contains(d.ProcessStatus));
|
|
}
|
|
}
|
|
if (!(req.ApprovalStatus == "全部" || string.IsNullOrEmpty(req.ApprovalStatus)))
|
|
{
|
|
clientPredicate = clientPredicate.And(d => req.ApprovalStatusList.Contains(d.ApprovalStatus));
|
|
}
|
|
//var clientRatingQuery = DbContext.Client_Rating.Where(x => !x.IsDeleted && x.ProcessStatus == "已审批" && x.RatingStartDate <= valueDate && x.RatingDeadLine >= valueDate);
|
|
|
|
var query = from source in DbContext.client.Where(clientPredicate)
|
|
//join clientRating in clientRatingQuery on source.id equals clientRating.ClientId into clientR
|
|
//from crating in clientR.DefaultIfEmpty()
|
|
//join creditRating in DbContext.credit_rating on crating.CreditRatingId equals creditRating.id into creditR
|
|
//from rating in creditR.DefaultIfEmpty()
|
|
join cl in DbContext.clientlevel on source.LevelId equals cl.id into clientL
|
|
from clientlevel in clientL.DefaultIfEmpty()
|
|
join ca in DbContext.ClientAuditLog on source.ApprovalLogId equals ca.id into calog
|
|
from ca in calog.DefaultIfEmpty()
|
|
select new ClientLinq
|
|
{
|
|
id = source.id,
|
|
Number = source.Number,
|
|
Name = source.Name,
|
|
Level = clientlevel == null ? "" : clientlevel.LevelName,
|
|
|
|
ProcessStatus = source.ProcessStatus,
|
|
ProcessRoleName = "",
|
|
//CreditRatingId = rating == null ? 0 : rating.id,
|
|
//CreditRatingName = rating == null ? "" : rating.CreditName,
|
|
ProcessOrderId = source.ProcessOrderId,
|
|
ProcessOrderBranch = source.ProcessOrderBranch,
|
|
ApprovalStatus = source.ApprovalStatus,
|
|
ApprovalOrderId = source.ApprovalOrderId,
|
|
|
|
CreditDirection = source.CreditDirection,
|
|
CreditYear = source.CreditYear,
|
|
CreditDeadline = source.CreditDeadline,
|
|
CreditTemp = source.CreditTemp,
|
|
CreditTempDeadline = source.CreditTempDeadline,
|
|
OptId = source.OptId,
|
|
OptName = source.OptName,
|
|
OptDate = source.OptDate,
|
|
Type = source.Type,
|
|
IdentificationNumber = source.IdentificationNumber,
|
|
Phone = source.Phone,
|
|
Address = source.Address,
|
|
Email = source.Email,
|
|
LevelId = source.LevelId,
|
|
Capitalbalance = source.Capitalbalance,
|
|
PendingMarginCallPayment = source.PendingMarginCallPayment,
|
|
Seller = source.Seller,
|
|
CustomerManager = source.CustomerManager,
|
|
CustomerManagerId = source.CustomerManagerId,
|
|
SalesDepartmentId = source.SalesDepartmentId,
|
|
ProcessOptDate = source.ProcessOptDate,
|
|
EvaluateOfValidity = source.EvaluateOfValidity,
|
|
EvaluateDate = source.EvaluateDate,
|
|
AppropriatenessDegree = source.AppropriatenessDegree,
|
|
RiskServiceDegree = source.RiskServiceDegree,
|
|
ProtocolSignDate = source.ProtocolSignDate,
|
|
ProperClientClass = source.ProperClientClass,
|
|
CustomerNature = source.CustomerNature,
|
|
CustomerNature1 = source.CustomerNature1,
|
|
CustomerNature2 = source.CustomerNature2,
|
|
TradingInstType = source.TradingInstType,
|
|
Guid = source.Guid,
|
|
PostalAddress = source.PostalAddress,
|
|
PostalCode = source.PostalCode,
|
|
LicenseCode = source.LicenseCode,
|
|
RegisteredCapital = source.RegisteredCapital,
|
|
ActualBeneficiary = source.ActualBeneficiary,
|
|
ActualController = source.ActualController,
|
|
RegisteredAddress = source.RegisteredAddress,
|
|
FinancialSituation = source.FinancialSituation,
|
|
InvestmentExperience = source.InvestmentExperience,
|
|
IsIndustryConnectVariety = source.IsIndustryConnectVariety,
|
|
TransactionTarget = source.TransactionTarget,
|
|
InvestmentTerm = source.InvestmentTerm,
|
|
IsRealControl = source.IsRealControl,
|
|
DerivativesInvestmentVarieties = source.DerivativesInvestmentVarieties,
|
|
FundsSource = source.FundsSource,
|
|
AcceptableLoss = source.AcceptableLoss,
|
|
RiskPreference = source.RiskPreference,
|
|
BadFaithRecord = source.BadFaithRecord,
|
|
IsEvaluate = source.IsEvaluate,
|
|
QuestionnaireScore = source.QuestionnaireScore,
|
|
IsAcceptHighRiskService = source.IsAcceptHighRiskService,
|
|
AppropriatenessAssessor = source.AppropriatenessAssessor,
|
|
IsRequireConversionTypes = source.IsRequireConversionTypes,
|
|
IsAssessmentResultChange = source.IsAssessmentResultChange,
|
|
Remark = source.Remark,
|
|
ChangeReasonAndEvaluationResults = source.ChangeReasonAndEvaluationResults,
|
|
DisbeliefRecord = source.DisbeliefRecord,
|
|
LicenseType = source.LicenseType,
|
|
ClientType = source.ClientType,
|
|
BusinessType = source.BusinessType,
|
|
InstitutionalAttributes = source.InstitutionalAttributes,
|
|
Region = source.Region,
|
|
BoundSide = source.BoundSide,
|
|
SettlementCurrency = source.SettlementCurrency,
|
|
IsTradeCredit = source.IsTradeCredit,
|
|
IsCreditOn = source.IsCreditOn,
|
|
AgreementBookNo = source.AgreementBookNo,
|
|
AgreementBookType = source.AgreementBookType,
|
|
Seat = source.Seat,
|
|
MarginOptionType = source.MarginOptionType,
|
|
RightProtocolSignDate = source.RightProtocolSignDate,
|
|
ProtocolSignVersion = source.ProtocolSignVersion,
|
|
ExpectedReturn2 = source.ExpectedReturn2,
|
|
ProductNumber = source.ProductNumber,
|
|
SamePeer = source.SamePeer,
|
|
AdminFullName = source.AdminFullName,
|
|
AdminRegisteredNum = source.AdminRegisteredNum,
|
|
NFICode = source.NFICode,
|
|
CounterpartyCode = source.CounterpartyCode,
|
|
ParentId = source.ParentId,
|
|
IsDocShowParentName = source.IsDocShowParentName,
|
|
MainProtocolCode = source.MainProtocolCode,
|
|
SupProtocolCode = source.SupProtocolCode,
|
|
Abbreviation = source.Abbreviation,
|
|
ClearingAgency = source.ClearingAgency,
|
|
SupProtocolDate = source.SupProtocolDate,
|
|
IsCentralClearing = source.IsCentralClearing,
|
|
CentralClearingPaltform = source.CentralClearingPaltform,
|
|
TradingPaltform = source.TradingPaltform,
|
|
LEICode = source.LEICode,
|
|
IsListed = source.IsListed,
|
|
Department = source.Department,
|
|
ServiceType = source.ServiceType,
|
|
LicenseValidTimeStr = source.LicenseValidTimeStr == "30001231" ? "长期有效" : source.LicenseValidTime.Value.ToString("yyyy-MM-dd"),
|
|
auditLog = ca,
|
|
ClientRight = source.ClientRight,
|
|
ProxyEmail = source.ProxyEmail,
|
|
SwapTradeType = source.SwapTradeType,
|
|
UnifiedSocialCreditCode=source.UnifiedSocialCreditCode,
|
|
SettleFileNumber= source.SettleFileNumber,
|
|
Manager=source.Manager,
|
|
OutNumber=source.OutNumber,
|
|
BusinessUseType = source.BusinessUseType,
|
|
ManagerSocialCreditCode=source.ManagerSocialCreditCode,
|
|
ManagerAbbreviation=source.ManagerAbbreviation,
|
|
};
|
|
|
|
if (req.Groupid != null && req.Groupid.Any())
|
|
{
|
|
var users = UserBLL.GetApprovalProcessGroupUser(req.Groupid);
|
|
query = query.Where(x => x.auditLog != null && users.Contains(x.auditLog.OptId));
|
|
}
|
|
if (req.TraderIds != null && req.TraderIds.Any())
|
|
{
|
|
query = query.Where(x => x.auditLog != null && req.TraderIds.Contains(x.auditLog.OptId));
|
|
}
|
|
if (req.ApprovaOptDateStart.HasValue && req.ApprovaOptDateStart != DateTime.MinValue)
|
|
{
|
|
query = query.Where(x => x.auditLog != null && x.auditLog.OptDate >= req.ApprovaOptDateStart.Value);
|
|
}
|
|
if (req.ApprovaOptDateeEnd.HasValue && req.ApprovaOptDateeEnd != DateTime.MinValue)
|
|
{
|
|
var approvaOptDateeEnd = req.ApprovaOptDateeEnd.Value.AddDays(1);
|
|
query = query.Where(x => x.auditLog != null && x.auditLog.OptDate < approvaOptDateeEnd);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(req.OptType))
|
|
{
|
|
query = query.Where(x => x.auditLog != null && x.auditLog.OptType.Contains(req.OptType));
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(req.sidx))
|
|
{
|
|
req.sidx = "id";
|
|
req.sord = "desc";
|
|
}
|
|
DbContext.SetDebugLog();
|
|
var retListResult = query.ToSearchList(req, true);
|
|
if (retListResult == null || retListResult.rows == null || !retListResult.rows.Any())
|
|
{
|
|
return retListResult;
|
|
}
|
|
var clientIds = retListResult.rows.Select(x => x.id).ToList();
|
|
var clientRatingList = DbContext.Client_Rating.AsNoTracking().Where(x => clientIds.Contains(x.ClientId) && !x.IsDeleted && x.ProcessStatus == "已审批" && x.RatingStartDate <= valueDate && x.RatingDeadLine >= valueDate).ToList();
|
|
List<CreditRating> creditRatingList = null;
|
|
if (clientRatingList != null && clientRatingList.Count > 0)
|
|
{
|
|
var creditRatingIds = clientRatingList.Where(x => x.CreditRatingId > 0).Select(x => x.CreditRatingId).Distinct().ToList();
|
|
if (creditRatingIds != null && creditRatingIds.Count > 0)
|
|
{
|
|
creditRatingList = DbContext.credit_rating.AsNoTracking().Where(p => creditRatingIds.Contains(p.id)).ToList();
|
|
}
|
|
}
|
|
if (clientRatingList == null)
|
|
{
|
|
clientRatingList = new List<ClientRating>();
|
|
}
|
|
if (creditRatingList == null)
|
|
{
|
|
creditRatingList = new List<CreditRating>();
|
|
}
|
|
|
|
|
|
var processLogs = DbContext.processlog.Where(x => clientIds.Contains(x.TypeId.Value) && x.ProcessType == "OpenProcess" && x.ProcessStatus == "拒绝审批").ToList().AsQueryable();
|
|
|
|
|
|
var appropriatenessAssessorList = ClientDataModelV1.GetAppropriatenessAssessor(false);
|
|
if (appropriatenessAssessorList == null)
|
|
{
|
|
appropriatenessAssessorList = new List<SelectItem>();
|
|
}
|
|
|
|
var parentIds = retListResult.rows.Where(p => p.ParentId > 0).Select(p => p.ParentId).Distinct().ToList();
|
|
List<Client> parentList = null;
|
|
if (parentIds != null && parentIds.Count > 0)
|
|
{
|
|
parentList = DbContext.client.AsNoTracking().Where(d => parentIds.Contains(d.id)).ToList();
|
|
}
|
|
if (parentList == null)
|
|
{
|
|
parentList = new List<Client>();
|
|
}
|
|
var yldic = DictionaryBLL.GetDictionary("适当性客户分类");
|
|
if (yldic == null)
|
|
{
|
|
yldic = new YLDictionary();
|
|
}
|
|
|
|
List<ClientDuty> clientDuties = DbContext.clientduty.AsNoTracking().Where(p => p.ApprovalOrder < 1 && clientIds.Contains((int)p.ClientId)).ToList();
|
|
if (clientDuties == null)
|
|
{
|
|
clientDuties = new List<ClientDuty>();
|
|
}
|
|
|
|
List<ClientMeta> clientMetas = DbContext.ClientMeta.AsNoTracking().Where(a => clientIds.Contains(a.ClientId)).ToList();
|
|
if (clientMetas == null)
|
|
{
|
|
clientMetas = new List<ClientMeta>();
|
|
}
|
|
|
|
var clientLinqs = retListResult.rows.ToList();
|
|
var service = new ClientLinqExtendService(this, clientLinqs).ExtendClientLinqQuery(clientIds); //构建查询条件
|
|
var index = 0;
|
|
var roles = ApprovalGradeDataService.getAllRoles();
|
|
|
|
foreach (var clientLinq in clientLinqs)
|
|
{
|
|
var clientRating = clientRatingList.FirstOrDefault(d => d.ClientId == clientLinq.id);
|
|
if (clientRating != null)
|
|
{
|
|
var creditRating = creditRatingList.FirstOrDefault(d => d.id == clientRating.CreditRatingId);
|
|
clientLinq.CreditRatingId = creditRating == null ? 0 : creditRating.id;
|
|
clientLinq.CreditRatingName = creditRating == null ? "" : creditRating.CreditName;
|
|
}
|
|
clientLinq.ProcessRoleId = GetApprovalRoleId(openProcessList.ToList(), clientLinq.ApprovalOrderId, clientLinq.ProcessOrderBranch);
|
|
clientLinq.ApprovalRole = roles.Where(x => x.Id == clientLinq.ProcessRoleId)?.FirstOrDefault()?.Name;
|
|
if (clientLinq.ApprovalStatus == "审批中")
|
|
{
|
|
clientLinq.ApprovalStatus = GetApprovalStatus(openProcessList.ToList(), clientLinq.ApprovalStatus, clientLinq.ApprovalOrderId, clientLinq.ProcessOrderBranch);
|
|
}
|
|
service.ExtendForEach(index).ExtendProcessRoleName(processLogs).ExtendAll(req.ValueDate.Value, appropriatenessAssessorList, parentList, yldic, clientDuties, clientRatingList, clientMetas);
|
|
index++;
|
|
}
|
|
|
|
return retListResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// AccountOpeningProcess/clientList
|
|
/// 导出可选列
|
|
/// </summary>
|
|
public List<ClientLinq> SearchOpeningProcessListForDown(ClientReq req)
|
|
{
|
|
//系统交易日
|
|
var valueDate = valuedateBLL.ValueDate;
|
|
if (!req.ValueDate.HasValue)
|
|
{
|
|
req.ValueDate = valueDate;
|
|
}
|
|
var clientPredicate = CreatePredicate(req, true);
|
|
if (req.ProcessStatus == "全部" || string.IsNullOrEmpty(req.ProcessStatus))
|
|
{
|
|
clientPredicate = clientPredicate.And(s => s.ProcessStatus != "已开户" && s.ProcessStatus != "已销户" && s.ProcessStatus != "已休眠");
|
|
}
|
|
else
|
|
{
|
|
clientPredicate = clientPredicate.And(d => req.ProcessStatusList.Contains(d.ProcessStatus) || (req.ProcessStatusList.Contains("审批中") && d.ProcessStatus.Contains("审批中")));
|
|
}
|
|
var clientRatingQuery = DbContext.Client_Rating.Where(x => !x.IsDeleted && x.ProcessStatus == "已审批" && x.RatingStartDate <= valueDate && x.RatingDeadLine >= valueDate);
|
|
var query = from source in DbContext.client
|
|
join clientRating in clientRatingQuery on source.id equals clientRating.ClientId into clientR
|
|
from crating in clientR.DefaultIfEmpty()
|
|
join creditRating in DbContext.credit_rating on crating.CreditRatingId equals creditRating.id into creditR
|
|
from rating in creditR.DefaultIfEmpty()
|
|
join cl in DbContext.clientlevel on source.LevelId equals cl.id into clientL
|
|
from clientlevel in clientL.DefaultIfEmpty()
|
|
select new ClientLinq
|
|
{
|
|
id = source.id,
|
|
Number = source.Number,
|
|
Name = source.Name,
|
|
Level = clientlevel == null ? "" : clientlevel.LevelName,
|
|
CreditDirection = source.CreditDirection,
|
|
CreditYear = source.CreditYear,
|
|
CreditDeadline = source.CreditDeadline,
|
|
CreditTemp = source.CreditTemp,
|
|
CreditTempDeadline = source.CreditTempDeadline,
|
|
OptId = source.OptId,
|
|
OptName = source.OptName,
|
|
OptDate = source.OptDate,
|
|
Type = source.Type,
|
|
IdentificationNumber = source.IdentificationNumber,
|
|
Phone = source.Phone,
|
|
Address = source.Address,
|
|
Email = source.Email,
|
|
LevelId = source.LevelId,
|
|
Capitalbalance = source.Capitalbalance,
|
|
PendingMarginCallPayment = source.PendingMarginCallPayment,
|
|
Seller = source.Seller,
|
|
CustomerManagerId = source.CustomerManagerId,
|
|
CustomerManager = source.CustomerManager,
|
|
SalesDepartmentId = source.SalesDepartmentId,
|
|
ProcessStatus = source.ProcessStatus,
|
|
ProtocolSignDate = source.ProtocolSignDate,
|
|
LicenseCode = source.LicenseCode,
|
|
PostalAddress = source.PostalAddress,
|
|
PostalCode = source.PostalCode,
|
|
EvaluateOfValidity = source.EvaluateOfValidity,
|
|
EvaluateDate = source.EvaluateDate,
|
|
ProperClientClass = source.ProperClientClass,
|
|
EndureLevel = source.EndureLevel,
|
|
//ProcessRoleId = proce.roleId,
|
|
ProcessRoleName = "",
|
|
ProcessOptDate = source.ProcessOptDate,
|
|
RejectOrderId = source.RejectOrderId,
|
|
CustomerNature = source.CustomerNature,
|
|
RegisteredCapital = source.RegisteredCapital,
|
|
ActualBeneficiary = source.ActualBeneficiary,
|
|
ActualController = source.ActualController,
|
|
RegisteredAddress = source.RegisteredAddress,
|
|
Remark = source.Remark,
|
|
CreditRatingId = rating == null ? 0 : rating.id,
|
|
CreditRatingName = rating == null ? "" : rating.CreditName,
|
|
ClientType = source.ClientType,
|
|
BusinessType = source.BusinessType,
|
|
InstitutionalAttributes = source.InstitutionalAttributes,
|
|
LicenseType = source.LicenseType,
|
|
IsTradeCredit = source.IsTradeCredit,
|
|
IsCreditOn = source.IsCreditOn,
|
|
SamePeer = source.SamePeer
|
|
};
|
|
|
|
query = query.OrderByDescending(q => q.ProcessOptDate);
|
|
|
|
var retListResult = query.ToList();
|
|
|
|
var openProcessList = yldb.approvalprocess.Where(x => x.processType == "OpenProcess").ToArray();
|
|
|
|
foreach (var clientLinq in retListResult)
|
|
{
|
|
if (clientLinq.ProcessOrderId < 1)
|
|
{
|
|
clientLinq.ProcessRoleId = openProcessList.FirstOrDefault()?.roleId;
|
|
}
|
|
else
|
|
{
|
|
clientLinq.ProcessRoleId = openProcessList.FirstOrDefault(n => n.order == clientLinq.ProcessOrderId)?.roleId;
|
|
}
|
|
new ClientLinqExtendService(this, clientLinq).ExtendEvaluateDate().ExtendProcessRoleName().ExtendClientDuty();
|
|
}
|
|
|
|
return retListResult;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 查询client--客户信息审批数据
|
|
/// </summary>
|
|
public SearchListResult<ClientLinq> SearchEditclientList(ClientReq req, Expression<Func<Client, bool>> clientPredicate = null)
|
|
{
|
|
if (!req.ValueDate.HasValue)
|
|
{
|
|
req.ValueDate = valuedateBLL.ValueDate;
|
|
}
|
|
var query = from client in DbContext.client
|
|
join cl in DbContext.clientlevel on client.LevelId equals cl.id into clientL
|
|
from clientlevel in clientL.DefaultIfEmpty()
|
|
join ca in DbContext.ClientAuditLog on client.ApprovalLogId equals ca.id into calog
|
|
from clientAuditLog in calog.DefaultIfEmpty()
|
|
where clientAuditLog != null && clientAuditLog.OptType == req.OptType && client.ApprovalStatus == req.ApprovalStatus
|
|
select new
|
|
{
|
|
client,
|
|
clientlevel,
|
|
clientAuditLog
|
|
};
|
|
var lists = query.ToList();
|
|
|
|
var lists2 = new List<ClientLinq>();
|
|
foreach (var item in lists)
|
|
{
|
|
var c = new ClientLinq();
|
|
var newclient = item.clientAuditLog.Changes == null ? item.client : ClientHelper.Deserialize(item.clientAuditLog.Changes);
|
|
c.id = item.client.id;
|
|
c.Number = newclient.Number;
|
|
c.Name = newclient.Name;
|
|
c.Level = item.clientlevel != null ? item.clientlevel.LevelName : "";
|
|
c.CreditDirection = newclient.CreditDirection;
|
|
c.CreditYear = newclient.CreditYear;
|
|
c.CreditDeadline = newclient.CreditDeadline;
|
|
c.CreditTemp = newclient.CreditTemp;
|
|
c.CreditTempDeadline = newclient.CreditTempDeadline;
|
|
c.CreatorId = newclient.CreatorId;
|
|
c.CreatorName = newclient.CreatorName;
|
|
c.CreateDate = newclient.CreateDate;
|
|
c.OptId = newclient.OptId;
|
|
c.OptName = newclient.OptName;
|
|
c.OptDate = newclient.OptDate;
|
|
c.Type = newclient.Type;
|
|
c.IdentificationNumber = newclient.IdentificationNumber;
|
|
c.Phone = newclient.Phone;
|
|
c.Address = newclient.Address;
|
|
c.Email = newclient.Email;
|
|
c.LevelId = newclient.LevelId;
|
|
c.Capitalbalance = newclient.Capitalbalance;
|
|
c.PendingMarginCallPayment = newclient.PendingMarginCallPayment;
|
|
c.Seller = newclient.Seller;
|
|
c.CustomerManager = newclient.CustomerManager;
|
|
c.CustomerManagerId = newclient.CustomerManagerId;
|
|
c.SalesDepartmentId = newclient.SalesDepartmentId;
|
|
c.ProcessStatus = newclient.ProcessStatus;
|
|
c.ProcessOptDate = newclient.ProcessOptDate;
|
|
c.ProcessOrderId = newclient.ProcessOrderId;
|
|
c.ProcessOrderBranch = item.client.ProcessOrderBranch;
|
|
c.ApprovalStatus = item.client.ApprovalStatus;
|
|
c.ApprovalOrderId = item.client.ApprovalOrderId;
|
|
c.EvaluateOfValidity = newclient.EvaluateOfValidity;
|
|
c.EvaluateDate = newclient.EvaluateDate;
|
|
c.EvaluateExpireDate = newclient.EvaluateExpireDate;
|
|
c.AppropriatenessDegree = newclient.AppropriatenessDegree;
|
|
c.RiskServiceDegree = newclient.RiskServiceDegree;
|
|
c.ProtocolSignDate = newclient.ProtocolSignDate;
|
|
c.RightProtocolSignDate = newclient.RightProtocolSignDate;
|
|
c.ProtocolSignVersion = newclient.ProtocolSignVersion;
|
|
c.ProperClientClass = newclient.ProperClientClass;
|
|
c.CustomerNature = newclient.CustomerNature;
|
|
c.CustomerNature1 = newclient.CustomerNature1;
|
|
c.CustomerNature2 = newclient.CustomerNature2;
|
|
c.Guid = newclient.Guid;
|
|
c.PostalAddress = newclient.PostalAddress;
|
|
c.PostalCode = newclient.PostalCode;
|
|
c.LicenseCode = newclient.LicenseCode;
|
|
c.RegisteredCapital = newclient.RegisteredCapital;
|
|
c.ActualBeneficiary = newclient.ActualBeneficiary;
|
|
c.ActualController = newclient.ActualController;
|
|
c.RegisteredAddress = newclient.RegisteredAddress;
|
|
c.FinancialSituation = newclient.FinancialSituation;
|
|
c.InvestmentExperience = newclient.InvestmentExperience;
|
|
c.IsIndustryConnectVariety = newclient.IsIndustryConnectVariety;
|
|
c.TransactionTarget = newclient.TransactionTarget;
|
|
c.InvestmentTerm = newclient.InvestmentTerm;
|
|
c.IsRealControl = newclient.IsRealControl;
|
|
c.IsSmallAndMicroEnterprises = newclient.IsSmallAndMicroEnterprises;
|
|
c.DerivativesInvestmentVarieties = newclient.DerivativesInvestmentVarieties;
|
|
c.FundsSource = newclient.FundsSource;
|
|
c.AcceptableLoss = newclient.AcceptableLoss;
|
|
c.RiskPreference = newclient.RiskPreference;
|
|
c.ExpectedReturn2 = newclient.ExpectedReturn2;
|
|
c.BadFaithRecord = newclient.BadFaithRecord;
|
|
c.IsEvaluate = newclient.IsEvaluate;
|
|
c.QuestionnaireScore = newclient.QuestionnaireScore;
|
|
c.IsAcceptHighRiskService = newclient.IsAcceptHighRiskService;
|
|
c.AppropriatenessAssessor = newclient.AppropriatenessAssessor;
|
|
c.IsRequireConversionTypes = newclient.IsRequireConversionTypes;
|
|
c.IsAssessmentResultChange = newclient.IsAssessmentResultChange;
|
|
c.Remark = newclient.Remark;
|
|
c.ChangeReasonAndEvaluationResults = newclient.ChangeReasonAndEvaluationResults;
|
|
c.DisbeliefRecord = newclient.DisbeliefRecord;
|
|
c.LicenseType = newclient.LicenseType;
|
|
c.ClientType = newclient.ClientType;
|
|
c.ProductNumber = newclient.ProductNumber;
|
|
c.BusinessType = newclient.BusinessType;
|
|
c.InstitutionalAttributes = newclient.InstitutionalAttributes;
|
|
c.Region = newclient.Region;
|
|
c.IsTradeCredit = newclient.IsTradeCredit;
|
|
c.IsCreditOn = newclient.IsCreditOn;
|
|
c.SamePeer = newclient.SamePeer;
|
|
c.AdminFullName = newclient.AdminFullName;
|
|
c.AdminRegisteredNum = newclient.AdminRegisteredNum;
|
|
c.NFICode = newclient.NFICode;
|
|
c.CounterpartyCode = newclient.CounterpartyCode;
|
|
c.ParentId = newclient.ParentId;
|
|
c.BoundSide = newclient.BoundSide;
|
|
c.SettlementCurrency = newclient.SettlementCurrency;
|
|
c.IsDocShowParentName = newclient.IsDocShowParentName;
|
|
c.AgreementBookNo = newclient.AgreementBookNo;
|
|
c.AgreementBookType = newclient.AgreementBookType;
|
|
c.Seat = newclient.Seat;
|
|
c.MainProtocolCode = newclient.MainProtocolCode;
|
|
c.SupProtocolCode = newclient.SupProtocolCode;
|
|
c.Abbreviation = newclient.Abbreviation;
|
|
c.ClearingAgency = newclient.ClearingAgency;
|
|
c.MarginOptionType = newclient.MarginOptionType;
|
|
c.ConfirmBookMode = newclient.ConfirmBookMode;
|
|
c.SupProtocolDate = newclient.SupProtocolDate;
|
|
c.IsInsided = newclient.IsInsided;
|
|
c.IsSendRecovery = newclient.IsSendRecovery;
|
|
c.IsCentralClearing = newclient.IsCentralClearing;
|
|
c.CentralClearingPaltform = newclient.CentralClearingPaltform;
|
|
c.TradingPaltform = newclient.TradingPaltform;
|
|
c.LEICode = newclient.LEICode;
|
|
c.IsListed = newclient.IsListed;
|
|
c.Department = newclient.Department;
|
|
c.ServiceType = newclient.ServiceType;
|
|
c.TradingInstTypeName = DBModels.Enums.TradingInstTypeUtil.GetDesc(newclient.TradingInstType);
|
|
c.LicenseValidTimeStr = newclient.LicenseValidTimeStr == "30001231" ? "长期有效" : newclient.LicenseValidTime == null ? "" : newclient.LicenseValidTime.Value.ToString("yyyy-MM-dd");
|
|
c.auditLog = item.clientAuditLog;
|
|
c.MetaDic = newclient.MetaDic;
|
|
lists2.Add(c);
|
|
}
|
|
|
|
var searchlist = lists2.Where(x => 1 == 1);
|
|
|
|
if (!string.IsNullOrEmpty(req.Name))
|
|
{
|
|
searchlist = searchlist.Where(d => d.Name.ToLower().Contains(req.Name.ToLower()));
|
|
}
|
|
if (!string.IsNullOrEmpty(req.LicenseCode))
|
|
{
|
|
searchlist = searchlist.Where(d => (d.LicenseCode ?? "").Contains(req.LicenseCode));
|
|
}
|
|
if (!string.IsNullOrEmpty(req.ProperClientClass))
|
|
{
|
|
var list =
|
|
(from source in DictionaryBLL.GetDictionaryItems("适当性客户分类")
|
|
join name in req.ProperClientClassList
|
|
on source.ShortName equals name
|
|
select source.ShortName).ToList();
|
|
searchlist = searchlist.Where(d => list.Contains(d.ProperClientClass));
|
|
}
|
|
if (req.CustomerManagerIds != null && req.CustomerManagerIds.Any(n => n > 0))
|
|
{
|
|
var _clientIds = GetClientIdsByCustomerManagerIds(req.CustomerManagerIds.ToList());
|
|
searchlist = searchlist.Where(d => _clientIds.Contains(d.id));
|
|
}
|
|
if (!string.IsNullOrEmpty(req.CustomerManagerString))
|
|
{
|
|
searchlist = searchlist.Where(d => req.CustomerManagerString.Contains(d.CustomerManager));
|
|
}
|
|
if (req.IsTradeCredit != null)
|
|
{
|
|
searchlist = searchlist.Where(d => req.IsTradeCredit == d.IsTradeCredit);
|
|
}
|
|
if (req.Groupid != null && req.Groupid.Any())
|
|
{
|
|
var users = UserBLL.GetApprovalProcessGroupUser(req.Groupid);
|
|
searchlist = searchlist.Where(x => x.auditLog != null && users.Contains(x.auditLog.OptId));
|
|
}
|
|
if (req.ProcessStatus != "ALL")
|
|
{
|
|
//全部:代表已开户和已销户(客户列表)的客户
|
|
if (req.ProcessStatus == "全部" || string.IsNullOrEmpty(req.ProcessStatus))
|
|
{
|
|
searchlist = searchlist.Where(d => d.ProcessStatus == "已开户" || d.ProcessStatus == "已休眠" || d.ProcessStatus == "已销户");
|
|
}
|
|
else
|
|
{
|
|
searchlist = searchlist.Where(d => req.ProcessStatusList.Contains(d.ProcessStatus));
|
|
}
|
|
}
|
|
if (req.TraderIds != null && req.TraderIds.Any())
|
|
{
|
|
searchlist = searchlist.Where(x => x.auditLog != null && req.TraderIds.Contains(x.auditLog.OptId));
|
|
}
|
|
if (req.ApprovaOptDateStart.HasValue && req.ApprovaOptDateStart != DateTime.MinValue)
|
|
{
|
|
searchlist = searchlist.Where(x => x.auditLog != null && x.auditLog.OptDate >= req.ApprovaOptDateStart.Value);
|
|
}
|
|
if (req.ApprovaOptDateeEnd.HasValue && req.ApprovaOptDateeEnd != DateTime.MinValue)
|
|
{
|
|
var approvaOptDateeEnd = req.ApprovaOptDateeEnd.Value.AddDays(1);
|
|
searchlist = searchlist.Where(x => x.auditLog != null && x.auditLog.OptDate < approvaOptDateeEnd);
|
|
}
|
|
if (req.TagIds != null && req.TagIds.Count > 0)
|
|
{
|
|
var tradeTagIdQuery = from tt in DbContext.client_tag
|
|
where req.TagIds.Contains(tt.TagId)
|
|
select tt.ClientId;
|
|
searchlist = searchlist.Where(p => tradeTagIdQuery.Contains(p.id));
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(req.sidx))
|
|
{
|
|
req.sidx = "id";
|
|
req.sord = "desc";
|
|
}
|
|
|
|
var retListResult = searchlist.AsQueryable().ToSearchList(req);
|
|
|
|
if (retListResult == null || retListResult.rows == null || !retListResult.rows.Any())
|
|
{
|
|
return retListResult;
|
|
}
|
|
|
|
var clientProcessList = yldb.approvalprocess.Where(x => x.processType == "ClientProcess").ToArray();
|
|
|
|
var lastSettlementDate = EodOperationBase.GetLastSettlementDate(DateTime.Now.Date);
|
|
var cashinCashoutSumQuery = from c in yldb.ClientCashInCashOut
|
|
where c.Comments == "信用风险亏损" && c.HappenDate == req.ValueDate
|
|
&& (c.State == "已确认" || c.State == "已结算")
|
|
group c by c.ClientId into g
|
|
select new
|
|
{
|
|
ClientId = g.Key,
|
|
CashSum = g.Sum(n => n.Money)
|
|
};
|
|
var cashinCashoutSumQueryDic = cashinCashoutSumQuery.ToDictionary(n => n.ClientId);
|
|
|
|
var clientIds = retListResult.rows.Select(p => p.id).Distinct().ToList();
|
|
|
|
var appropriatenessAssessorList = ClientDataModelV1.GetAppropriatenessAssessor();
|
|
|
|
var parentClientIds = retListResult.rows.Where(p => p.ParentId > 0).Select(p => p.ParentId).Distinct().ToList();
|
|
List<Client> parentClientList = null;
|
|
if (parentClientIds != null && parentClientIds.Any())
|
|
{
|
|
parentClientList = DbContext.client.Where(p => parentClientIds.Contains(p.id)).AsNoTracking().ToList();
|
|
}
|
|
if (parentClientList == null)
|
|
{
|
|
parentClientList = new List<Client>();
|
|
}
|
|
List<ClientMeta> clientMetaList = DbContext.ClientMeta.Where(p => clientIds.Contains(p.ClientId)).AsNoTracking().ToList();
|
|
if (clientMetaList == null)
|
|
{
|
|
clientMetaList = new List<ClientMeta>();
|
|
}
|
|
var yldic = DictionaryBLL.GetDictionary("适当性客户分类");
|
|
|
|
List<ClientDuty> clientDutyList = DbContext.clientduty.Where(p => p.ApprovalOrder < 1 && clientIds.Contains((int)p.ClientId)).AsNoTracking().ToList();
|
|
if (clientDutyList == null)
|
|
{
|
|
clientDutyList = new List<ClientDuty>();
|
|
}
|
|
|
|
List<ClientRating> clientRatingList = DbContext.Client_Rating.Where(p => clientIds.Contains(p.ClientId) && !p.IsDeleted && p.RatingStartDate <= req.ValueDate.Value && p.RatingDeadLine >= req.ValueDate.Value && p.ProcessStatus == "已审批").AsNoTracking().ToList();
|
|
if (clientRatingList == null)
|
|
{
|
|
clientRatingList = new List<ClientRating>();
|
|
}
|
|
|
|
Dictionary<int, double> realtime_Trade_RiskList = null;
|
|
Dictionary<int, double> eod_Trade_RiskList = null;
|
|
if (lastSettlementDate < req.ValueDate.Value)
|
|
{
|
|
var gQuery = from p in yldb.realtime_trade_risk
|
|
where clientIds.Contains((int)p.ClientId) && "持仓".Equals(p.VolType)
|
|
group p by p.ClientId.Value into g
|
|
select new { g.Key, sum = g.Sum(n => n.CreditExposure) };
|
|
|
|
realtime_Trade_RiskList = gQuery.ToDictionary(t => t.Key, t => t.sum);
|
|
}
|
|
else
|
|
{
|
|
eod_Trade_RiskList = yldb.eod_trade_risk.Where(p => clientIds.Contains(p.ClientId) && p.ValueDate == req.ValueDate.Value).AsEnumerable().GroupBy(p => (int)p.ClientId).ToDictionary(t => t.Key, t => t.Sum(d => d.CreditExposure));
|
|
}
|
|
if (realtime_Trade_RiskList == null)
|
|
{
|
|
realtime_Trade_RiskList = new Dictionary<int, double>();
|
|
}
|
|
if (eod_Trade_RiskList == null)
|
|
{
|
|
eod_Trade_RiskList = new Dictionary<int, double>();
|
|
}
|
|
var roles = ApprovalGradeDataService.getAllRoles();
|
|
|
|
foreach (var clientLinq in retListResult.rows)
|
|
{
|
|
if (lastSettlementDate < req.ValueDate.Value)
|
|
{
|
|
if (realtime_Trade_RiskList.ContainsKey(clientLinq.id))
|
|
{
|
|
clientLinq.Exposure = realtime_Trade_RiskList[clientLinq.id];
|
|
}
|
|
//clientLinq.Exposure = realtime_Trade_RiskList.Where(o => o.ClientId == clientLinq.id && o.VolType == "持仓").Sum(o => (double?)o.CreditExposure) ?? 0;
|
|
}
|
|
else
|
|
{
|
|
if (eod_Trade_RiskList.ContainsKey(clientLinq.id))
|
|
{
|
|
clientLinq.Exposure = eod_Trade_RiskList[clientLinq.id];
|
|
}
|
|
//clientLinq.Exposure = eod_Trade_RiskList.Where(o => o.ClientId == clientLinq.id && o.ValueDate == req.ValueDate.Value).Sum(o => (double?)o.CreditExposure) ?? 0;
|
|
}
|
|
if (cashinCashoutSumQueryDic.TryGetValue(clientLinq.id, out var dicItem1))
|
|
{
|
|
clientLinq.CreditRiskLoss = dicItem1.CashSum ?? 0;
|
|
}
|
|
var mate = clientLinq.MetaDic;
|
|
new ClientLinqExtendService(this, clientLinq, req.CheckContactExpired).ExtendAll(req.ValueDate.Value, appropriatenessAssessorList, parentClientList, yldic, clientDutyList, clientRatingList, clientMetaList);
|
|
clientLinq.MetaDic = mate;
|
|
clientLinq.ProcessRoleId = GetApprovalRoleId(clientProcessList.ToList(), clientLinq.ApprovalOrderId, clientLinq.ProcessOrderBranch);
|
|
clientLinq.ApprovalRole = roles.Where(x => x.Id == clientLinq.ProcessRoleId)?.FirstOrDefault()?.Name;
|
|
if (clientLinq.ApprovalStatus == "审批中")
|
|
{
|
|
clientLinq.ApprovalStatus = GetApprovalStatus(clientProcessList.ToList(), clientLinq.ApprovalStatus, clientLinq.ApprovalOrderId, clientLinq.ProcessOrderBranch);
|
|
}
|
|
}
|
|
return retListResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 筛选条件
|
|
/// </summary>
|
|
public Expression<Func<Client, bool>> CreatePredicate(ClientReq req, bool ignoreProcessStatus = false, bool skipHavePosition = false)
|
|
{
|
|
var predicate = PredicateBuilder.True<Client>();
|
|
if (!string.IsNullOrEmpty(req.Number))
|
|
{
|
|
predicate = predicate.And(d => d.Number.Contains(req.Number));
|
|
}
|
|
if (!string.IsNullOrEmpty(req.Name))
|
|
{
|
|
predicate = predicate.And(d => d.Name.Contains(req.Name));
|
|
}
|
|
|
|
if (req.TagIds != null && req.TagIds.Count > 0)
|
|
{
|
|
var tradeTagIdQuery = from tt in DbContext.client_tag
|
|
where req.TagIds.Contains(tt.TagId)
|
|
select tt.ClientId;
|
|
predicate = predicate.And(p => tradeTagIdQuery.Contains(p.id));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(req.BoundSide))
|
|
{
|
|
predicate = predicate.And(o => o.BoundSide == (req.BoundSide == "0" ? BoundSideEnum.北向 : BoundSideEnum.南向));
|
|
}
|
|
if (req.id > 0)
|
|
{
|
|
req.ClientIds = new List<int>() { req.id.Value };
|
|
}
|
|
|
|
var clients = new List<int>();
|
|
if (req.HaveMarginAmount || req.HavePayableFund || req.HavePosition || req.HaveClosedPayableFund || req.HaveTotalAsset)
|
|
{
|
|
if (req.HaveMarginAmount)
|
|
{
|
|
clients.AddRange(ClientBalanceUtility.GetHaveMarginAmount(req.ValueDate.Value, req.MarginShownType));
|
|
}
|
|
if (req.HavePayableFund)
|
|
{
|
|
clients.AddRange(ClientBalanceUtility.GetHavePayableFund(req.ValueDate.Value, req.MarginShownType));
|
|
}
|
|
if (req.HavePosition && !skipHavePosition)
|
|
{
|
|
clients.AddRange(ClientBalanceUtility.GetHavePositionClientIds(req.ValueDate.Value));
|
|
}
|
|
if (req.HaveClosedPayableFund)
|
|
{
|
|
clients.AddRange(ClientBalanceUtility.GetClosePayableFundClientIds(req.ValueDate.Value, req.MarginShownType));
|
|
}
|
|
if (req.HaveTotalAsset)
|
|
{
|
|
clients.AddRange(ClientBalanceUtility.GetTotalAssetClientIds(req.ValueDate.Value));
|
|
}
|
|
if (!clients.Any() && req.ValueDate <= EodOperationBase.GetLastSettlementDate(req.ValueDate ?? valuedateBLL.ValueDate))
|
|
{
|
|
return PredicateBuilder.False<Client>();
|
|
}
|
|
}
|
|
if (req.IsSmallAndMicroEnterprises != null)
|
|
{
|
|
if (req.IsSmallAndMicroEnterprises.Count > 0)
|
|
{
|
|
predicate = predicate.And(s => req.IsSmallAndMicroEnterprises.Contains(s.IsSmallAndMicroEnterprises));
|
|
}
|
|
|
|
}
|
|
if (req.CurUserClientIds.Any())
|
|
{
|
|
if (req.ClientIds.Any() && clients.Any())
|
|
{
|
|
clients = req.CurUserClientIds.Intersect(req.ClientIds).Intersect(clients).ToList();
|
|
predicate = predicate.And(d => clients.Contains(d.id));
|
|
}
|
|
else if (!req.ClientIds.Any() && clients.Any())
|
|
{
|
|
clients = req.CurUserClientIds.Intersect(clients).ToList();
|
|
predicate = predicate.And(d => clients.Contains(d.id));
|
|
}
|
|
else if (req.ClientIds.Any() && !clients.Any())
|
|
{
|
|
req.ClientIds = req.CurUserClientIds.Intersect(req.ClientIds).ToList();
|
|
predicate = predicate.And(d => req.ClientIds.Contains(d.id));
|
|
}
|
|
else
|
|
{
|
|
predicate = predicate.And(d => req.CurUserClientIds.Contains(d.id));
|
|
}
|
|
}
|
|
//else
|
|
//{
|
|
// predicate = predicate.And(d => req.CurUserClientIds.Contains(d.id));
|
|
//}
|
|
|
|
//LevelIdsList
|
|
if (req.LevelIds != null && req.LevelIds.Any(n => n > 0))
|
|
{
|
|
predicate = predicate.And(d => req.LevelIds.Contains(d.LevelId.Value));
|
|
}
|
|
|
|
//资信等级过滤条件不要了
|
|
|
|
//客户性质
|
|
if (req.CustomerNatures != null && req.CustomerNatures.Any(n => n > 0))
|
|
{
|
|
predicate = predicate.And(d => req.CustomerNatures.Contains(d.CustomerNature.Value));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.LicenseCode))
|
|
{
|
|
predicate = predicate.And(d => d.LicenseCode.Contains(req.LicenseCode));
|
|
}
|
|
|
|
if (req.ProtocolSignDateStart != DateTime.MinValue)
|
|
{
|
|
predicate = predicate.And(d => d.ProtocolSignDate >= req.ProtocolSignDateStart);
|
|
}
|
|
if (req.ProtocolSignDateEnd != DateTime.MinValue)
|
|
{
|
|
var protocolSignDateEnd = req.ProtocolSignDateEnd.AddDays(1);
|
|
predicate = predicate.And(d => d.ProtocolSignDate < protocolSignDateEnd);
|
|
}
|
|
if (req.CustomerManagerIds != null && req.CustomerManagerIds.Any(n => n > 0))
|
|
{
|
|
var clientIds = GetClientIdsByCustomerManagerIds(req.CustomerManagerIds.ToList());
|
|
predicate = predicate.And(d => clientIds.Contains(d.id));
|
|
}
|
|
if (!string.IsNullOrEmpty(req.OptName))
|
|
{
|
|
predicate = predicate.And(d => d.OptName.Contains(req.OptName));
|
|
}
|
|
|
|
if (req.OptDateStart != DateTime.MinValue)
|
|
{
|
|
predicate = predicate.And(d => d.OptDate >= req.OptDateStart);
|
|
}
|
|
|
|
if (req.OptDateEnd != DateTime.MinValue)
|
|
{
|
|
var OptDateTemp = req.OptDateEnd.AddDays(1);
|
|
predicate = predicate.And(d => d.OptDate < OptDateTemp);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.Guid))
|
|
{
|
|
predicate = predicate.And(d => d.Guid.Contains(req.Guid));
|
|
}
|
|
|
|
//All:代表所有状态的客户
|
|
if (!ignoreProcessStatus && req.ProcessStatus != "ALL")
|
|
{
|
|
//全部:代表已开户和已销户(客户列表)的客户
|
|
if (req.ProcessStatus == "全部" || req.ProcessStatus == null)
|
|
{
|
|
predicate = predicate.And(d => d.ProcessStatus == "已开户" || d.ProcessStatus == "已休眠" || d.ProcessStatus == "已销户");
|
|
}
|
|
else
|
|
{
|
|
predicate = predicate.And(d => d.ProcessStatus == req.ProcessStatus);
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.ProperClientClass))
|
|
{
|
|
var list =
|
|
(from source in DictionaryBLL.GetDictionaryItems("适当性客户分类")
|
|
join name in req.ProperClientClassList
|
|
on source.ShortName equals name
|
|
select source.ShortName).ToList();
|
|
|
|
predicate = predicate.And(d => list.Contains(d.ProperClientClass));
|
|
}
|
|
if (PS.Config.Is物产中大)
|
|
{
|
|
if (!string.IsNullOrEmpty(req.ParentIds))
|
|
{
|
|
predicate = predicate.And(d => req.ParentIdList.Contains(d.ParentId));
|
|
}
|
|
}
|
|
|
|
//确认书模板
|
|
if (req.ConfirmBookMode != null && req.ConfirmBookMode != "-1")
|
|
{
|
|
if (req.ConfirmBookMode.Equals("单章版"))
|
|
{
|
|
predicate = predicate.And(o => o.SupProtocolDate.HasValue);
|
|
}
|
|
else
|
|
{
|
|
predicate = predicate.And(o => !o.SupProtocolDate.HasValue);
|
|
}
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.CustomerManagerString))
|
|
{
|
|
predicate = predicate.And(d => req.CustomerManagerString.Contains(d.CustomerManager));
|
|
}
|
|
//if (req.CustomerManagerIds != null && req.CustomerManagerIds.Any(n => n > 0))
|
|
//{
|
|
// predicate = predicate.And(d => string.IsNullOrEmpty(d.CustomerManagerId)?false: d.CustomerManagerId.Contains));
|
|
//}
|
|
if (req.IsTradeCredit != null)
|
|
{
|
|
predicate = predicate.And(d => req.IsTradeCredit == d.IsTradeCredit);
|
|
}
|
|
|
|
if (req.PendingMarginCallPayment != null)
|
|
{
|
|
predicate = predicate.And(d => d.PendingMarginCallPayment == req.PendingMarginCallPayment);
|
|
}
|
|
|
|
if (req.SwapHedgingType != null)
|
|
{
|
|
predicate = predicate.And(d => d.SwapHedgingType == req.SwapHedgingType);
|
|
}
|
|
|
|
return predicate;
|
|
}
|
|
|
|
public List<ClientSimpleDto> GetClientListByWhere(Expression<Func<Client, bool>> expression)
|
|
{
|
|
return DbContext.client.AsNoTracking().Where(expression).Select(p => new ClientSimpleDto
|
|
{
|
|
id = p.id,
|
|
Name = p.Name,
|
|
LevelId = p.LevelId,
|
|
}).ToList();
|
|
}
|
|
|
|
public static List<int> GetClientIdsByCustomerManagerIds(List<int> customerManagerIds)
|
|
{
|
|
var clientIds = new List<int>();
|
|
customerManagerIds.ForEach(a =>
|
|
{
|
|
var clients = DbContextFactory.GetClientDbContext(null).client.Where(b => b.CustomerManagerId.Contains(a + "")).AsQueryable();
|
|
if (clients.Any())
|
|
{
|
|
clientIds.AddRange(clients.Select(b => b.id));
|
|
}
|
|
});
|
|
return clientIds;
|
|
}
|
|
|
|
|
|
public string GetProductName(int ClientId)
|
|
{
|
|
var clientMeta = DbContext.ClientMeta.FirstOrDefault(o => o.ClientId == ClientId && o.MetaKey == "产品名称");
|
|
return clientMeta == null ? "" : clientMeta.MetaValue;
|
|
}
|
|
|
|
|
|
public string GetTrusteeAgency(int ClientId)
|
|
{
|
|
var clientMeta = DbContext.ClientMeta.FirstOrDefault(o => o.ClientId == ClientId && o.MetaKey == "托管机构");
|
|
return clientMeta?.MetaValue;
|
|
}
|
|
}
|
|
|
|
public class ClientLinqExtendService : ClientBaseService
|
|
{
|
|
ClientLinq _clientLinq;
|
|
readonly bool _checkExpired;
|
|
List<approvalprocess> _processes;
|
|
Dictionary<int, string> _roleDic;
|
|
List<ClientLinq> _clientLinqs;
|
|
//List<ClientDuty> _clientDutyList;
|
|
List<ClientDuty> _clientDutys;
|
|
//public int index { get; set; } = 0;
|
|
int _contractId, _ownerId;
|
|
ClientDuty _clientDuty;
|
|
IQueryable<ClientDuty> _clientDutyQuery;
|
|
|
|
|
|
public ClientLinqExtendService(ClientBaseService baseService, ClientLinq baseValue, bool checkExpired = false) : base(baseService)
|
|
{
|
|
_roleDic = null;
|
|
_processes = null;
|
|
_checkExpired = checkExpired;
|
|
_clientLinq = baseValue ?? throw new ArgumentNullException(nameof(baseValue));
|
|
}
|
|
|
|
public ClientLinqExtendService(ClientBaseService baseService, List<ClientLinq> baseValues, bool checkExpired = false) : base(baseService)
|
|
{
|
|
_roleDic = null;
|
|
_processes = null;
|
|
_checkExpired = checkExpired;
|
|
_clientLinqs = baseValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 扩展枚举描述
|
|
/// </summary>
|
|
public ClientLinqExtendService ExtendEnumName(List<SelectItem> appropriatenessAssessorList = null, List<Client> parentList = null)
|
|
{
|
|
if (appropriatenessAssessorList == null)
|
|
{
|
|
appropriatenessAssessorList = ClientDataModelV1.GetAppropriatenessAssessor(false);
|
|
}
|
|
|
|
if (_clientLinq == null) return this;
|
|
|
|
if (_clientLinq.CustomerNature > 0)
|
|
{
|
|
_clientLinq.CustomerNatureName = ((CustomerNatureEnum)_clientLinq.CustomerNature.Value).ToString();
|
|
}
|
|
if (_clientLinq.InvestmentTerm > 0)
|
|
{
|
|
_clientLinq.InvestmentTermName = EnumHelper.GetDescriptionByName((InvestmentTermEnum)_clientLinq.InvestmentTerm.Value).ToString();
|
|
}
|
|
if (_clientLinq.FundsSource > 0)
|
|
{
|
|
_clientLinq.FundsSourceName = ((FundsSourceEnum)_clientLinq.FundsSource.Value).ToString();
|
|
}
|
|
if (_clientLinq.BadFaithRecord > 0)
|
|
{
|
|
_clientLinq.BadFaithRecordName = ((BadFaithRecordEnum)_clientLinq.BadFaithRecord.Value).ToString();
|
|
}
|
|
if (_clientLinq.ParentId > 0)
|
|
{
|
|
if (parentList == null)
|
|
{
|
|
_clientLinq.ParentName = DataCacheProvider.GetClientDataSource().GetData(_clientLinq.ParentId).Name;
|
|
}
|
|
else
|
|
{
|
|
var parent = parentList.FirstOrDefault(p => p.id == _clientLinq.ParentId);
|
|
_clientLinq.ParentName = parent?.Name;
|
|
}
|
|
}
|
|
if (_clientLinq.AppropriatenessAssessor > 0)
|
|
{
|
|
_clientLinq.AppropriatenessAssessorName = appropriatenessAssessorList.Where(a => a.Value == _clientLinq.AppropriatenessAssessor.ToString()).FirstOrDefault()?.Text;
|
|
}
|
|
|
|
//if (_clientLinq.DerivativesInvestmentVarietyList.Any())
|
|
//{
|
|
// List<string> list = new List<string>();
|
|
// _clientLinq.DerivativesInvestmentVarieties = string.Join(",", _clientLinq.DerivativesInvestmentVarietyList.Select(a => ((DerivativesInvestmentVarietiesEnum)a).ToString()));
|
|
//}
|
|
|
|
//if (_clientLinq.AppropriatenessDegree > 0)
|
|
//{
|
|
// _clientLinq.AppropriatenessDegreeName = ((AppropriatenessDegreeEnum)_clientLinq.AppropriatenessDegree.Value).ToString();
|
|
//}
|
|
//if (_clientLinq.RiskServiceDegree > 0)
|
|
//{
|
|
// _clientLinq.RiskServiceDegreeName = ((RiskServiceDegreeEnum)_clientLinq.RiskServiceDegree.Value).ToString();
|
|
//}
|
|
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取适当性评估到期日
|
|
/// </summary>
|
|
/// <param name="EvaluateDate"></param>
|
|
/// <param name="EvaluateOfValidity">
|
|
/// 仅支持:
|
|
/// <para>3个月</para>
|
|
/// <para>6个月</para>
|
|
/// <para>9个月</para>
|
|
/// <para>12个月</para>
|
|
/// <para>长期</para>
|
|
/// </param>
|
|
/// <returns></returns>
|
|
public static DateTime GetEvaluateDate(DateTime? EvaluateDate, string EvaluateOfValidity)
|
|
{
|
|
var deadLine = DateTime.MaxValue;
|
|
if (EvaluateDate != null
|
|
&& !string.IsNullOrWhiteSpace(EvaluateOfValidity))
|
|
{
|
|
deadLine = EvaluateDate.Value;
|
|
switch (EvaluateOfValidity)
|
|
{
|
|
case "3个月":
|
|
deadLine = deadLine.AddMonths(3);
|
|
break;
|
|
case "6个月":
|
|
deadLine = deadLine.AddMonths(6);
|
|
break;
|
|
case "9个月":
|
|
deadLine = deadLine.AddMonths(9);
|
|
break;
|
|
case "12个月":
|
|
deadLine = deadLine.AddMonths(12);
|
|
break;
|
|
default:
|
|
deadLine = DateTime.MaxValue.Date;
|
|
break;
|
|
}
|
|
}
|
|
return deadLine;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 扩展评估有效期
|
|
/// </summary>
|
|
public ClientLinqExtendService ExtendEvaluateDate()
|
|
{
|
|
if (_clientLinq == null) return this;
|
|
|
|
//EvaluateOfValidity:3个月、6个月、12个月、长期
|
|
if (_clientLinq.EvaluateOfValidity == "长期")
|
|
{
|
|
return this;
|
|
}
|
|
|
|
if (_clientLinq.EvaluateDate != null && _clientLinq.EvaluateOfValidity != null)
|
|
{
|
|
DateTime dt = ClientLinqExtendService.GetEvaluateDate(_clientLinq.EvaluateDate, _clientLinq.EvaluateOfValidity);
|
|
_clientLinq.EvaluateDays = Math.Max((dt - DateTime.Today).Days, 0).ToString();
|
|
}
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 扩展客户联系人
|
|
/// </summary>
|
|
public ClientLinqExtendService ExtendClientDuty(List<ClientDuty> clientDuties = null)
|
|
{
|
|
if (_clientLinq == null) return this;
|
|
|
|
var valueDate = valuedateBLL.ValueDate;
|
|
var clientId = _clientLinq.id;
|
|
|
|
|
|
//非开户列表走此逻辑
|
|
if (_clientDutyQuery == null)
|
|
{
|
|
_contractId = (DbContext.contactype.AsNoTracking().FirstOrDefault(x => x.ContactType == "联系人")?.id) ?? -1; //联系人Id
|
|
_ownerId = (DbContext.contactype.AsNoTracking().FirstOrDefault(x => x.ContactType == "法人")?.id) ?? -1; //法人Id
|
|
_clientDutyQuery = DbContext.clientduty.OrderBy(x => x.id);
|
|
}
|
|
_clientDutys = _clientDutyQuery.Where(x => x.ClientId == clientId).ToList();
|
|
|
|
|
|
if (_clientDutys.Any())
|
|
{
|
|
|
|
_clientDuty = _clientDutys.FirstOrDefault(x => x.ContactTypeId.Split(',').Any(t => t == _contractId.ToString())); //联系人
|
|
|
|
if (_clientDuty == null)
|
|
{
|
|
_clientDuty = _clientDutys.FirstOrDefault(x => x.ContactTypeId.Split(',').Any(t => t == _ownerId.ToString()));//法人
|
|
|
|
}
|
|
if (_clientDuty != null)
|
|
{
|
|
_clientLinq.ContactName = _clientDuty.ContactName;
|
|
_clientLinq.Phone = _clientDuty.PhoneNumber;
|
|
_clientLinq.Email = _clientDuty.Email;
|
|
_clientLinq.IdentificationNumber = _clientDuty.IdCardNo;
|
|
if (_clientDuty.IdCardType > 0)
|
|
{
|
|
_clientLinq.IdentificationType = ((IdCardTypeEnum)_clientDuty.IdCardType).ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (_checkExpired)
|
|
{
|
|
var existQuery = clientDuties.Where(cd => cd.ClientId == clientId && cd.DeadLine != null && (cd.ContactTypeId.Contains("1") || cd.ContactTypeId.Contains("2")));
|
|
_clientLinq.IsExistContactExpired = existQuery.Any(cd => cd.DeadLine < valueDate);
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public ClientLinqExtendService ExtendProcessRoleName(IQueryable<Processlog> processLogs = null)
|
|
{
|
|
if (_clientLinq == null) return this;
|
|
|
|
if (_roleDic == null)
|
|
{
|
|
using (var edb = new ErpBaseContext())
|
|
{
|
|
_roleDic = edb.Roles.Select(n => new { n.Id, n.Name }).ToDictionary(n => n.Id, n => n.Name);
|
|
}
|
|
}
|
|
|
|
if (_clientLinq.ProcessStatus == "已拒绝")
|
|
{
|
|
var RejectOrderId = _clientLinq.RejectOrderId;
|
|
if (_processes == null)
|
|
{
|
|
_processes = yldb.approvalprocess.Where(x => x.processType == "OpenProcess").ToList();
|
|
}
|
|
var rejectProcess = _processes.FirstOrDefault(x => x.order == RejectOrderId);
|
|
if (rejectProcess == null)
|
|
{
|
|
_clientLinq.ProcessRoleName = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
_roleDic.TryGetValue(rejectProcess.roleId, out var roleName);
|
|
_clientLinq.ProcessRoleName = roleName ?? string.Empty;
|
|
}
|
|
|
|
if (processLogs != null)
|
|
{
|
|
var clientId = _clientLinq.id;
|
|
var rejectLog = processLogs.LastOrDefault(x => x.TypeId.Value == clientId);
|
|
//如果可以查到拒绝原因,会在列表的状态列的title显示拒绝原因,否则title默认为状态本身
|
|
_clientLinq.RejectLog = rejectLog == null ? _clientLinq.ProcessStatus : rejectLog.Log;
|
|
}
|
|
else
|
|
{
|
|
_clientLinq.RejectLog = _clientLinq.ProcessStatus;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_clientLinq.ProcessRoleId != null)
|
|
{
|
|
_roleDic.TryGetValue(_clientLinq.ProcessRoleId.Value, out var roleName);
|
|
_clientLinq.ProcessRoleName = roleName ?? string.Empty;
|
|
}
|
|
//非拒绝状态的状态列title默认为状态本身
|
|
_clientLinq.RejectLog = _clientLinq.ProcessStatus;
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 扩展客户评级
|
|
/// </summary>
|
|
public ClientLinqExtendService ExtendClientRating(DateTime searchDate, List<ClientRating> clientRatingList = null)
|
|
{
|
|
if (_clientLinq == null) return this;
|
|
|
|
var clientId = _clientLinq.id;
|
|
ClientRating cr;
|
|
if (clientRatingList == null)
|
|
{
|
|
//1.如果存在多条deadline相同,再按审批时间排序 2.否则,直接返回该条记录
|
|
cr = DbContext.Client_Rating.Where(x => !x.IsDeleted && x.ClientId == clientId && x.ProcessStatus == "已审批"
|
|
&& x.RatingStartDate <= searchDate && x.RatingDeadLine >= searchDate)
|
|
.OrderByDescending(n => n.RatingDeadLine).ThenByDescending(n => n.ProcessOptDate).FirstOrDefault();
|
|
}
|
|
else
|
|
{
|
|
cr = clientRatingList.Where(x => !x.IsDeleted && x.ClientId == clientId && x.ProcessStatus == "已审批"
|
|
&& x.RatingStartDate <= searchDate && x.RatingDeadLine >= searchDate)
|
|
.OrderByDescending(n => n.RatingDeadLine).ThenByDescending(n => n.ProcessOptDate).FirstOrDefault();
|
|
}
|
|
|
|
_clientLinq.CreditRatingId = cr?.CreditRatingId ?? 0;
|
|
_clientLinq.CreditRatingName = cr?.CreditRatingStr;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 扩展自定义字段
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ClientLinqExtendService ExtendClientMetas(List<ClientMeta> clientMetaList = null)
|
|
{
|
|
if (_clientLinq == null) return this;
|
|
var clientId = _clientLinq.id;
|
|
if (clientMetaList == null)
|
|
{
|
|
_clientLinq.MetaDic = DbContext.ClientMeta.AsNoTracking().Where(a => a.ClientId == clientId).ToDictionary(a => a.MetaKey, a => a.MetaValue);
|
|
}
|
|
else
|
|
{
|
|
_clientLinq.MetaDic = clientMetaList.Where(a => a.ClientId == clientId).ToDictionary(a => a.MetaKey, a => a.MetaValue);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ClientLinqExtendService ExtendProtocolSignVersion()
|
|
{
|
|
if (_clientLinq == null) return this;
|
|
if (string.IsNullOrEmpty(_clientLinq.ProtocolSignVersion)) return this;
|
|
|
|
var yldic = DictionaryBLL.GetDictionary("协议签署版本");
|
|
var ProtocolSignVersionItems = yldic.GetList("协议签署版本", false);
|
|
_clientLinq.ProtocolSignVersion = ProtocolSignVersionItems.Where(a => a.Value == _clientLinq.ProtocolSignVersion).FirstOrDefault()?.Text;
|
|
return this;
|
|
}
|
|
|
|
public ClientLinqExtendService ExtendProperClientClass(YLDictionary yldic = null)
|
|
{
|
|
if (_clientLinq == null) return this;
|
|
if (string.IsNullOrEmpty(_clientLinq.ProperClientClass)) return this;
|
|
if (yldic == null)
|
|
{
|
|
yldic = DictionaryBLL.GetDictionary("适当性客户分类");
|
|
}
|
|
var ProperClientClassItems = yldic.GetList("适当性客户分类", false);
|
|
_clientLinq.ProperClientClass = ProperClientClassItems.Where(a => a.Value == _clientLinq.ProperClientClass).FirstOrDefault()?.Text;
|
|
return this;
|
|
}
|
|
|
|
|
|
public ClientLinqExtendService ExtendAll(DateTime searchDate, List<SelectItem> appropriatenessAssessorList = null, List<Client> parentList = null, YLDictionary yldic = null, List<ClientDuty> clientDuties = null, List<ClientRating> clientRatingList = null, List<ClientMeta> clientMetaList = null)
|
|
{
|
|
if (_clientLinq == null) return this;
|
|
|
|
ExtendEnumName(appropriatenessAssessorList, parentList);
|
|
ExtendProperClientClass(yldic);
|
|
ExtendEvaluateDate();
|
|
ExtendClientDuty(clientDuties);
|
|
ExtendClientRating(searchDate, clientRatingList);
|
|
ExtendClientMetas(clientMetaList);
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 循环扩展
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="IndexOutOfRangeException"></exception>
|
|
public ClientLinqExtendService ExtendForEach(int index)
|
|
{
|
|
if (_clientLinqs == null || _clientLinqs.Count == 0) return this;
|
|
|
|
if (index < 0 || index >= _clientLinqs.Count) throw new ServiceException("索引超过了ClientLinq集合的长度");
|
|
|
|
_clientLinq = _clientLinqs[index];
|
|
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询数据扩展
|
|
/// </summary>
|
|
/// <param name="clientIds"></param>
|
|
/// <returns></returns>
|
|
public ClientLinqExtendService ExtendClientLinqQuery(List<int> clientIds)
|
|
{
|
|
if (_clientLinqs == null || _clientLinqs.Count == 0) return this;
|
|
|
|
|
|
_contractId = (DbContext.contactype.AsNoTracking().FirstOrDefault(x => x.ContactType == "联系人")?.id) ?? -1;
|
|
_ownerId = (DbContext.contactype.AsNoTracking().FirstOrDefault(x => x.ContactType == "法人")?.id) ?? -1;
|
|
|
|
_clientDutyQuery =
|
|
DbContext.clientduty.Where(x => x.ApprovalOrder < 1 && clientIds.Contains(x.ClientId ?? 0)).OrderBy(x => x.ClientId).ToList().AsQueryable();
|
|
|
|
return this;
|
|
}
|
|
}
|
|
}
|