using YLErp.BLL;
namespace YLErp.Modules.EodModule.SettlementModule
{
///
/// 检查所有已开户的客户资信评级
///
class EodCheckClientRating : ClientBaseService
{
readonly EodSettlementContextBase _context;
public EodCheckClientRating(EodSettlementContextBase context) : base(context.UserInfo)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
}
///
/// 检查所有已开户的客户资信评级
///
public bool CheckClientRating()
{
var settleDate = _context.SettleDate;
//var canSelectCreditVariety = PS.Config.ClientElement.CanSelectCreditVariety;
//对当前“资信等级”快要到期的客户以某种方式进行提示,要求更新它的“资信等级”,如果逾期没有更新,【收盘操作】中应当可以检查出来,显示收盘不成功。
//必须审核通过!
//1.检查当日
var clientNames = CheckDateClientRating(settleDate);
string CheckMsg;
if (!string.IsNullOrWhiteSpace(clientNames))
{
CheckMsg = $"客户:{clientNames} ,在{settleDate:yyyy-MM-dd} 的资信评级不存在或未审核,请进入资信评级菜单检查 或者将该客户设为休眠状态!";
_context.RaiseError(CheckMsg, "");
return false;
}
//2.预警下一个交易日
var nextWorkDay = QdpModule.QdpCalendarHelper.GetNonHoliday(settleDate.AddDays(1));
var clientNamesNextDay = CheckDateClientRating(nextWorkDay);
if (!string.IsNullOrWhiteSpace(clientNamesNextDay))
{
CheckMsg = $"警告:客户:{clientNamesNextDay},在{nextWorkDay:yyyy-MM-dd} 的资信评级不存在或未审核,请提前进入资信评级菜单检查!";
_context.RaiseError(CheckMsg, "");
}
return true;
}
private string CheckDateClientRating(DateTime settleDate)
{
//历史收盘不验证
var nowDate = valuedateBLL.ValueDate;
if (nowDate > settleDate.Date)
{
return string.Empty;
}
//以下客户符合要求:有已审批的评级记录;当前系统日落在该客户已审批的评级记录里。
var meetCondition = from client in DbContext.client.Where(x => x.ProcessStatus == "已开户")
join clientrating in DbContext.Client_Rating.Where(x => !x.IsDeleted && x.ProcessStatus == "已审批")
on client.id equals clientrating.ClientId
where (settleDate >= clientrating.RatingStartDate) && (settleDate <= clientrating.RatingDeadLine)
select new
{
clientId = client.id
};
//以下已开户的客户但不在上述名单的会被筛选
var queryError = from client in DbContext.client.Where(x => x.ProcessStatus == "已开户")
where !meetCondition.Select(x => x.clientId).Contains(client.id)
select new
{
clientId = client.id,
clientName = client.Name
};
if (queryError.Any())
{
var clients = string.Join(" , ", queryError.Select(x => x.clientName).ToArray());
return clients;
}
return string.Empty;
}
}
}