Files
zszq-trs/YLErpDAL/Modules/ClientModule/ClientProcessLogService.cs
tengyufan 8afd449c40 feat(ClientBlack): 新增客户黑名单审批流程
- 黑名单新增、删除、批量导入、批量移出在配置审批节点后,审批通过才生效
- 新增黑名单待提交后可提交审批;仅首节点未审批时可撤回,进入后续节点禁止撤回
- 增加黑名单审批列表、审批弹窗、审批操作日志及状态筛选
- 支持审批配置中的“黑名单审批”流程及对应菜单、模块权限、操作权限
- 黑名单审批中禁止同名记录覆盖备注;已在黑名单中的同名导入会明确提示本次将修改备注
- 未配置审批节点时保持原有直接生效行为
- 增加黑名单审批状态机单测,39/39 通过
- 修正撤回全部失败时仍提示“撤回审批成功”的问题
2026-08-13 17:21:04 +08:00

892 lines
38 KiB
C#

using BaseOUDAL;
using NPOI.Util;
using Org.BouncyCastle.Crypto.Tls;
using Org.BouncyCastle.Ocsp;
using System.Linq.Expressions;
using YieldChain.Helpers;
using YLErp.Abstract;
using YLErp.BLL;
using YLErp.CustomizedBizLogic;
using YLErp.DBModels.Enums;
using YLErp.Helpers;
using YLErp.Model;
using YLErp.Model.Enum;
using YLErp.Modules.AppModule;
using YLErp.Modules.ClientModule.Constant;
using YLErp.Modules.SwapModule;
namespace YLErp.Modules.ClientModule
{
/// <summary>
/// 客户审批流程日志服务
/// <para>2021-03月开始增加了非客户审批的记录</para>
/// </summary>
public class ClientProcessLogService : ClientBaseService
{
public ClientProcessLogService(OptUserInfo userInfo) : base(userInfo)
{
}
/// <summary>
/// 查询client processlog
/// </summary>
public SearchListResult<ProcesslogViewModel> SearchList(ProcesslogReq req)
{
var predicate = ProcesslogReqUtil.CreatePredicate(req.ProcessType, req);
var query = from processlog in DbContext.processlog.Where(predicate)
select new ProcesslogViewModel
{
id = processlog.id,
TypeId = processlog.TypeId,
//ClientName = clientD.Name,
ProcessType = processlog.ProcessType,
ProcessStatus = processlog.ProcessStatus,
Log = processlog.Log,
Remark = processlog.Remark,
OptId = processlog.OptId,
CreateTime = processlog.CreateTime
};
if (string.IsNullOrEmpty(req.sidx))
{
req.sidx = "id";
req.sord = "desc";
}
var retListResult = query.ToSearchList(req);
foreach (var row in retListResult.rows)
{
row.OptName = UserBLL.GetById(row.OptId ?? 0)?.Name;
if (req.ProcessType == "OpenProcess")
{
row.ClientName = DataCacheProvider.GetClientDataSource().GetData(row.TypeId ?? 0)?.Name;
}
}
return retListResult;
}
/// <summary>
/// 查询client_rating processlog
/// </summary>
public SearchListResult<ProcesslogViewModel> SearchClientRatingList(ProcesslogReq req)
{
var predicate = ProcesslogReqUtil.CreatePredicate("CreditProcess", req);
var query = from processlog in DbContext.processlog.Where(predicate)
join client_Rating in DbContext.Client_Rating.Where(x => !x.IsDeleted) on processlog.TypeId equals client_Rating.id into c
from creditD in c.DefaultIfEmpty()
select new ProcesslogViewModel
{
id = processlog.id,
TypeId = processlog.TypeId,
ClientName = creditD.ClientName,
ProcessType = processlog.ProcessType,
ProcessStatus = processlog.ProcessStatus,
Log = processlog.Log,
OptId = processlog.OptId,
CreateTime = processlog.CreateTime
};
if (string.IsNullOrEmpty(req.sidx))
{
req.sidx = "id";
req.sord = "desc";
}
var retListResult = query.ToSearchList(req);
foreach (var row in retListResult.rows)
{
row.OptName = UserBLL.GetById(row.OptId ?? 0)?.Name;//OTC-8651
}
return retListResult;
}
#region----UpdateProcessLog----
/// <summary>
/// 客户开户审批
/// </summary>
public string UpdateProcessLog(int clientId, string status, string text)
{
if (string.IsNullOrEmpty(status))
{
throw new ServiceException("status参数不能为空");
}
var client = DbContext.client.FirstOrDefault(s => s.id == clientId);
if (client == null)
{
throw new ServiceException("客户数据不存在");
}
var clientlog = DbContext.ClientAuditLog.Find(client.ApprovalLogId);
var processType = clientlog.OptType.Contains("开户审批") ? "OpenProcess" : clientlog.OptType == "提交信息变更审批" ? "ClientProcess" : "";
try
{
if (DbContext.client_black.Any(c => c.Name == client.Name && ClientBlackApprovalPolicy.EffectiveStates.Contains(c.State)))
{
client.RejectOrderId = client.ApprovalOrderId;
client.ApprovalOrderId = -1;
client.ApprovalStatus = "已拒绝";
client.ApprovalOptDate = OptDate;
client.OptId = UserId;
client.OptName = UserName;
client.OptDate = OptDate;
DbContext.processlog.Add(new Processlog
{
TypeId = clientId,
ProcessType = processType,
ProcessStatus = "拒绝审批",
Log = text,
OptId = UserId,
CreateTime = OptDate
});
///日志记录
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientId,
OptType = "拒绝审批",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
var range = DbContext.client_file_audit.Where(x => x.ClientId == client.id).ToList();
DbContext.client_file_audit.RemoveRange(range);
DbContext.SaveChanges();
throw new ServiceException("该客户在黑名单中,审批拒绝");
}
//客户为产品时 并且可以交易品种包含场外互换时 拒绝审批
if (!string.IsNullOrEmpty(client.ClientType) && client.ClientType.Equals(ClientTypeEnum.产品.ToString()) && !string.IsNullOrEmpty(client.DerivativesInvestmentVarieties) && client.DerivativesInvestmentVarieties.Contains((int)DerivativesInvestmentVarietiesEnum.场外互换 + ""))
{
//获取产品投资人
var hasClientInvestors = DbContext.ClientInvestor.Where(t => t.ClientId == client.id && !"专业投资者".Equals(t.EligibilityType) && t.ShareRate > 0.2);
if (hasClientInvestors != null && hasClientInvestors.Count() > 0)
{
client.RejectOrderId = client.ApprovalOrderId;
client.ApprovalOrderId = -1;
client.ApprovalStatus = "已拒绝";
client.ApprovalOptDate = OptDate;
client.OptId = UserId;
client.OptName = UserName;
client.OptDate = OptDate;
DbContext.processlog.Add(new Processlog
{
TypeId = clientId,
ProcessType = processType,
ProcessStatus = "拒绝审批",
Log = "本客户为产品客户,存在非专业投资人权益比例大于20%情况,无法进行场外互换交易!",
OptId = UserId,
CreateTime = OptDate
});
///日志记录
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientId,
OptType = "拒绝审批",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
var range = DbContext.client_file_audit.Where(x => x.ClientId == client.id).ToList();
DbContext.client_file_audit.RemoveRange(range);
DbContext.SaveChanges();
throw new ServiceException("本客户为产品客户,存在非专业投资人权益比例大于20%情况,无法进行场外互换交易!");
}
}
if (status == "pass")
{
var openProcess = yldb.approvalprocess.Where(s => s.processType == processType).ToList();
var count = openProcess.Count();
if (count == 0)
{
return SetOpen(client, text, processType, clientlog.Changes);
}
var nextProcess = openProcess.Where(x => x.order > client.ApprovalOrderId && (x.node == client.ProcessOrderBranch || x.node == 0) && x.approvalGroupId == 0).OrderBy(o => o.order).FirstOrDefault();
if (nextProcess == null)
{
return SetOpen(client, text, processType, clientlog.Changes);
}
else
{
client.ApprovalOrderId = nextProcess.order;
}
//继续审批流转
client.ApprovalStatus = "审批中";
client.ProcessOptDate = OptDate;
client.OptId = UserId;
client.OptName = UserName;
client.OptDate = OptDate;
DbContext.processlog.Add(new Processlog
{
TypeId = clientId,
ProcessType = processType,
ProcessStatus = "通过审批",
Log = text,
OptId = UserId,
CreateTime = OptDate
});
///日志记录
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientId,
OptType = "通过审批",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
DbContext.SaveChanges();
return "提交成功";
}
else if (status == "reject")
{
client.RejectOrderId = client.ApprovalOrderId;
client.ApprovalOrderId = -1;
client.ApprovalStatus = "已拒绝";
client.ApprovalOptDate = OptDate;
client.OptId = UserId;
client.OptName = UserName;
client.OptDate = OptDate;
revertBankDutyFile(client.id);
DbContext.processlog.Add(new Processlog
{
TypeId = clientId,
ProcessType = processType,
ProcessStatus = "拒绝审批",
Log = text,
OptId = UserId,
CreateTime = OptDate
});
///日志记录
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientId,
OptType = "拒绝审批",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
var range = DbContext.client_file_audit.Where(x => x.ClientId == client.id).ToList();
DbContext.client_file_audit.RemoveRange(range);
DbContext.SaveChanges();
return "提交成功";
}
throw new ServiceException("status参数不支持:" + status);
}
catch (ServiceException)
{
throw;
}
catch (Exception ex)
{
LogFactory.GetLogger<ClientProcessLogService>().Error("提交开户审批", ex);
throw new ServiceException(ex.Message, ex);
}
}
/// <summary>
///
/// </summary>
private string SetOpen(Client client, string text, string processType, string changes)
{
var oldClient = client.Clone();
var preAuditStatus = DbContext.ClientMeta.FirstOrDefault(p => p.ClientId == client.id && p.MetaKey == ClientMetaKey.AuditPreStatus);
if (preAuditStatus != null)
{
DbContext.ClientMeta.Remove(preAuditStatus);
}
//设置成开户状态,写日志
if (processType == "OpenProcess")
{
client.ProcessOrderId = -2;
client.ProcessStatus = "已开户";
client.ProcessOptDate = OptDate;
}
client.ApprovalOrderId = -2;
client.ApprovalStatus = "审批通过";
client.ApprovalOptDate = OptDate;
client.OptId = UserId;
client.OptName = UserName;
client.OptDate = OptDate;
client.HadPass = 1;
if (string.IsNullOrEmpty(client.Number))
{
BizLogicSingleton.Instance.GenerateClientCode(client, DbContext.client);
}
if (processType == "ClientProcess")
{
if (!string.IsNullOrWhiteSpace(changes))
{
var ca = DbContext.ClientAuditLog.Where(x => x.id == client.ApprovalLogId && x.OptType == "提交信息变更审批").FirstOrDefault();
var newclient = ClientHelper.Deserialize(ca.Changes);
newclient.ApprovalOrderId = -2;
newclient.ApprovalStatus = "审批通过";
newclient.ApprovalOptDate = OptDate;
newclient.HadPass = 1;
client = new ClientSaveService(UserInfo).SaveEditData(newclient);
}
updateBankDutyFile(client.id);
}
//每一个成功开户的客户(即首次从【开户管理】转到【客户列表】),系统会自动在【资信等级】页面对该客户留下第一条“资信等级”记录,
//但是具体等级是什么,适用期限(生效日期、到期日期)是什么,都空着,待风控人员来填写;
if (!DbContext.Client_Rating.Any(x => !x.IsDeleted && x.ClientId == client.id))
{
var emptyRating = new ClientRating
{
ClientId = client.id,
ClientName = client.Name,
ClientNumber = client.Number,
Comments = "开户成功生成",
OptId = UserId,
OptName = UserName,
OptDate = OptDate,
RatingStartDate = valuedateBLL.ValueDate
};
emptyRating.RatingDeadLine = emptyRating.RatingStartDate.Value.AddYears(99);
var defaultRating = DbContext.credit_rating.Where(x => x.ValidState == "Valid").FirstOrDefault();
emptyRating.CreditRatingId = defaultRating?.id ?? 0;
emptyRating.CreditRatingStr = defaultRating?.CreditName;
emptyRating.ProcessStatus = "未审批";
emptyRating.ProcessOrderId = 0;
emptyRating.ProcessOptDate = DateTime.Now;
DbContext.Client_Rating.Add(emptyRating);
}
DbContext.processlog.Add(new Processlog
{
TypeId = client.id,
ProcessType = processType,
ProcessStatus = processType == "ClientProcess" ? "信息变更成功" : client.ProcessStatus,
Log = text,
OptId = UserId,
CreateTime = OptDate
});
//日志记录
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = client.id,
OptType = "通过审批",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
DbContext.SaveChanges();
new EtradingRuleService(this.OptUser).SendEtradingRuleToKafka(client.Number);
new ClientKafkaService().Send(client, oldClient);
return "提交成功";
}
public void updateBankDutyFile(int clientid)
{
using (var trans = BeginTransaction())
{
if (DbContext.bankcard.Where(b => b.ApprovalOrder != (int)ApprovalOrderEnum.审批作废 && b.ApprovalOrder != (int)ApprovalOrderEnum.无需审批 && b.ClientId == clientid).Any())
{
//新增
var add = DbContext.bankcard.Where(x => x.ApprovalOrder == (int)ApprovalOrderEnum.新增 && x.ClientId == clientid);
foreach (var item in add)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.无需审批;
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientid,
OptType = "新建银行卡",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
}
//导入
var upload = DbContext.bankcard.Where(x => x.ApprovalOrder == (int)ApprovalOrderEnum.导入 && x.ClientId == clientid);
foreach (var item in upload)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.无需审批;
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientid,
OptType = "导入银行卡",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
}
//失效
var inValid = DbContext.bankcard.Where(x => x.ApprovalOrder == (int)ApprovalOrderEnum.失效 && x.ClientId == clientid);
foreach (var item in inValid)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.无需审批;
item.ValidState = "InValid";
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientid,
OptType = "删除银行卡",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
}
//修改
var newupdate = DbContext.bankcard.Where(x => x.SourceId > 0 && x.ApprovalOrder != (int)ApprovalOrderEnum.审批作废 && x.ClientId == clientid).ToList();
var orderids = newupdate.Select(x => x.SourceId ?? 0).ToList();
var update = DbContext.bankcard.Where(x => orderids.Contains(x.id));
foreach (var item in update)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.无需审批;
var newitem = newupdate.Where(x => x.SourceId == item.id)?.FirstOrDefault();
var changeStr = DataChangeHelper.GetDataChanges(item, newitem).ToJson();
ObjectHelper.MapValues(item, newitem, "id", "ApprovalOrder", "SourceId");
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientid,
OptType = "编辑银行卡",
Changes = changeStr,
DataType = "C02",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
}
foreach (var item in newupdate)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.审批作废;
}
}
if (DbContext.clientduty.Where(b => b.ApprovalOrder != (int)ApprovalOrderEnum.审批作废 && b.ApprovalOrder != (int)ApprovalOrderEnum.无需审批 && b.ClientId == clientid).Any())
{
//新增
var add = DbContext.clientduty.Where(x => x.ApprovalOrder == (int)ApprovalOrderEnum.新增 && x.ClientId == clientid);
foreach (var item in add)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.无需审批;
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientid,
OptType = "新增客户人员",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
}
//导入
var upload = DbContext.clientduty.Where(x => x.ApprovalOrder == (int)ApprovalOrderEnum.导入 && x.ClientId == clientid);
foreach (var item in upload)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.无需审批;
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientid,
OptType = "导入客户人员",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
}
//删除
var delete = DbContext.clientduty.Where(x => x.ApprovalOrder == (int)ApprovalOrderEnum.删除 && x.ClientId == clientid);
foreach (var item in delete)
{
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientid,
OptType = "删除客户人员",
Changes = string.Empty,
DataType = "00",
OptId = UserId,
OptName = UserName,
OptDate = OptDate
});
}
DbContext.clientduty.RemoveRange(delete);
//修改
var newupdate = DbContext.clientduty.Where(x => x.SourceId > 0 && x.ApprovalOrder != (int)ApprovalOrderEnum.审批作废 && x.ClientId == clientid).ToList();
var orderids = newupdate.Select(x => x.SourceId ?? 0).ToList();
var update = DbContext.clientduty.Where(x => orderids.Contains(x.id));
foreach (var item in update)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.无需审批;
var newitem = newupdate.Copy().Where(x => x.SourceId == item.id)?.FirstOrDefault();
var changeStr = DataChangeHelper.GetDataChanges(item, newitem).ToJson();
ObjectHelper.MapValues(item, newitem, "id", "ApprovalOrder", "SourceId");
DbContext.ClientAuditLog.Add(new ClientAuditLog
{
ClientId = clientid,
OptType = "编辑客户人员",
Changes = changeStr,
DataType = "C02",
OptId = UserId,
OptName = UserName,
OptDate = DateTime.Now
});
}
foreach (var item in newupdate)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.审批作废;
}
}
if (DbContext.client_file.Where(b => b.ApprovalOrder != (int)ApprovalOrderEnum.审批作废 && b.ApprovalOrder != (int)ApprovalOrderEnum.无需审批 && b.ClientId == clientid).Any())
{
var fileservice = new ClientFileService(UserInfo);
//新增
var add = DbContext.client_file.Where(x => x.ApprovalOrder == (int)ApprovalOrderEnum.新增 && x.ClientId == clientid);
foreach (var item in add)
{
fileservice.NewFile_ApprovalOrde(item);
}
//文件废弃
var abandonment = DbContext.client_file.Where(x => x.ApprovalOrder == (int)ApprovalOrderEnum.文件废弃 && x.ClientId == clientid);
foreach (var item in abandonment)
{
fileservice.AbandonFile(item, true);
}
//文件删除
var delete = DbContext.client_file.Where(x => (x.ApprovalOrder == (int)ApprovalOrderEnum.失效 || x.ApprovalOrder == (int)ApprovalOrderEnum.删除) && x.ClientId == clientid);
foreach (var item in delete)
{
fileservice.DeleteFile(clientid, item.FileName, item.ProtocolNumber, true);
}
var newSourceId = DbContext.client_file.Where(x => x.SourceId > 0 && x.ApprovalOrder != (int)ApprovalOrderEnum.文件解除废弃 && x.ClientId == clientid).ToList();
var orderids = newSourceId.Select(x => x.SourceId ?? 0).ToList();
var update = DbContext.client_file.Where(x => orderids.Contains(x.id));
foreach (var item in update)
{
var newitem = newSourceId.Copy().Where(x => x.SourceId == item.id)?.FirstOrDefault();
if (newitem != null)
{
if (newitem.ApprovalOrder == (int)ApprovalOrderEnum.文件修改)
{
fileservice.UpdateData_ApprovalOrder(newitem);
item.ApprovalOrder = (int)ApprovalOrderEnum.无需审批;
}
else if (newitem.ApprovalOrder == (int)ApprovalOrderEnum.文件还原)
{
fileservice.RecoverFile_ApprovalOrder(item);
}
}
}
//文件中转删除
var delete2 = DbContext.client_file.Where(x => x.ApprovalOrder == (int)ApprovalOrderEnum.文件中转删除 && x.ClientId == clientid);
DbContext.client_file.RemoveRange(delete2);
}
DbContext.SaveChanges();
trans.Commit();
}
}
public void revertBankDutyFile(int clientId)
{
//新增
DbContext.bankcard.RemoveRange(DbContext.bankcard.Where(x => (x.ApprovalOrder == (int)ApprovalOrderEnum.新增 || x.ApprovalOrder == (int)ApprovalOrderEnum.导入) && x.ClientId == clientId));
DbContext.clientduty.RemoveRange(DbContext.clientduty.Where(x => (x.ApprovalOrder == (int)ApprovalOrderEnum.新增 || x.ApprovalOrder == (int)ApprovalOrderEnum.导入) && x.ClientId == clientId));
DbContext.client_file.RemoveRange(DbContext.client_file.Where(x => (x.ApprovalOrder == (int)ApprovalOrderEnum.新增 || x.ApprovalOrder == (int)ApprovalOrderEnum.文件修改) && x.ClientId == clientId));
DbContext.SaveChanges();
if (DbContext.bankcard.Where(b => b.ClientId == clientId && b.ApprovalOrder != (int)ApprovalOrderEnum.无需审批 && b.ApprovalOrder != (int)ApprovalOrderEnum.审批作废).Any())
{
var lists = DbContext.bankcard.Where(b => b.ClientId == clientId && b.ApprovalOrder != (int)ApprovalOrderEnum.无需审批 && b.ApprovalOrder != (int)ApprovalOrderEnum.审批作废).ToList();
foreach (var item in lists)
{
if (item.ApprovalOrder == (int)ApprovalOrderEnum.修改)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.审批作废;
}
else
{
item.ApprovalOrder = 0;
}
}
}
if (DbContext.clientduty.Where(b => b.ClientId == clientId && b.ApprovalOrder != (int)ApprovalOrderEnum.无需审批 && b.ApprovalOrder != (int)ApprovalOrderEnum.审批作废).Any())
{
var lists = DbContext.clientduty.Where(b => b.ClientId == clientId && b.ApprovalOrder != (int)ApprovalOrderEnum.无需审批 && b.ApprovalOrder != (int)ApprovalOrderEnum.审批作废).ToList();
foreach (var item in lists)
{
if (item.ApprovalOrder == (int)ApprovalOrderEnum.修改)
{
item.ApprovalOrder = (int)ApprovalOrderEnum.审批作废;
}
else
{
item.ApprovalOrder = 0;
}
}
}
if (DbContext.client_file.Where(b => b.ClientId == clientId && b.ApprovalOrder != (int)ApprovalOrderEnum.无需审批 && b.ApprovalOrder != (int)ApprovalOrderEnum.审批作废).Any())
{
var lists = DbContext.client_file.Where(b => b.ClientId == clientId && b.ApprovalOrder != (int)ApprovalOrderEnum.无需审批 && b.ApprovalOrder != (int)ApprovalOrderEnum.审批作废).ToList();
foreach (var item in lists)
{
item.ApprovalOrder = 0;
}
}
DbContext.SaveChanges();
}
#endregion
#region----UpdateProcessClient_RatingLog----
/// <summary>
/// 客户资信评级审批
/// </summary>
public string UpdateProcessClient_RatingLog(int clientRatingId, string status, string text)
{
if (clientRatingId < 1)
{
throw new ServiceException("参数传入有误");
}
var client_rating = DbContext.Client_Rating.Where(x => !x.IsDeleted).FirstOrDefault(x => x.id == clientRatingId);
if (client_rating == null)
{
throw new ServiceException("系统中没有该资信评级记录");
}
try
{
if (status == "pass")
{
var count = yldb.approvalprocess.Where(s => s.processType == "CreditProcess").Count();
if (count == 0)
{
return SetClientRatingOpen(client_rating, text);
}
var processOrderId = client_rating.ProcessOrderId + 1;
if (processOrderId > count)
{
return SetClientRatingOpen(client_rating, text);
}
//继续审批流转
client_rating.ProcessOrderId = processOrderId;
client_rating.ProcessOptDate = OptDate;
client_rating.OptId = UserId;
client_rating.OptName = UserName;
client_rating.OptDate = OptDate;
DbContext.processlog.Add(new Processlog
{
TypeId = clientRatingId,
ProcessType = "CreditProcess",
ProcessStatus = "通过审批",
Log = text,
OptId = UserId,
CreateTime = OptDate
});
DbContext.clientrating_log.Add(new ClientRatingLog
{
RatingId = processOrderId,
OptType = "通过审批",
OptId = UserId,
OptName = UserName,
OptDate = DateTime.Now
});
DbContext.SaveChanges();
return "提交成功";
}
else if (status == "reject")
{
client_rating.ProcessOrderId = -1;
client_rating.ProcessStatus = "已拒绝";
client_rating.ProcessOptDate = OptDate;
client_rating.OptId = UserId;
client_rating.OptName = UserName;
client_rating.OptDate = OptDate;
DbContext.processlog.Add(new Processlog
{
TypeId = clientRatingId,
ProcessType = "CreditProcess",
ProcessStatus = "审批拒绝",
Log = text,
OptId = UserId,
CreateTime = OptDate
});
DbContext.clientrating_log.Add(new ClientRatingLog
{
RatingId = clientRatingId,
OptType = "拒绝审批",
OptId = UserId,
OptName = UserName,
OptDate = DateTime.Now
});
DbContext.SaveChanges();
return "提交成功";
}
throw new ServiceException("status参数传入错误:" + status);
}
catch (ServiceException)
{
throw;
}
catch (Exception ex)
{
LogFactory.GetLogger<ClientProcessLogService>().Error("提交资信评级审批", ex);
throw new ServiceException(ex.Message, ex);
}
}
private string SetClientRatingOpen(ClientRating clientRating, string text)
{
//设置成资信评级审批状态
clientRating.ProcessOrderId = -2;
clientRating.ProcessStatus = "已审批";
clientRating.ProcessOptDate = OptDate;
clientRating.OptId = UserId;
clientRating.OptName = UserName;
clientRating.OptDate = OptDate;
DbContext.processlog.Add(new Processlog
{
TypeId = clientRating.id,
ProcessType = "CreditProcess",
ProcessStatus = "已审批",
Log = text,
OptId = UserId,
CreateTime = OptDate
});
DbContext.clientrating_log.Add(new ClientRatingLog
{
RatingId = clientRating.id,
OptType = "通过审批",
OptId = UserId,
OptName = UserName,
OptDate = DateTime.Now
});
DbContext.SaveChanges();
return "提交成功";
}
#endregion
/// <summary>
/// 记录日志
/// </summary>
public void SetLog(Processlog log, bool useSave = true)
{
if (log is null)
{
throw new ArgumentNullException(nameof(log));
}
DbContext.processlog.Add(log);
if (useSave)
{
DbContext.SaveChanges();
}
}
}
/// <summary>
///
/// </summary>
public static class ProcesslogReqUtil
{
public static Expression<Func<Processlog, bool>> CreatePredicate(string processType, ProcesslogReq req)
{
var predicate = PredicateBuilder.Create<Processlog>(n => n.ProcessType == processType);
if (req.TypeId > 0)
{
predicate = predicate.And(d => d.TypeId == req.TypeId);
}
if (!string.IsNullOrEmpty(req.ProcessType))
{
predicate = predicate.And(d => d.ProcessType.Contains(req.ProcessType));
}
if (!string.IsNullOrEmpty(req.ProcessStatus))
{
predicate = predicate.And(d => d.ProcessStatus.Contains(req.ProcessStatus));
}
if (!string.IsNullOrEmpty(req.Log))
{
predicate = predicate.And(d => d.Log.Contains(req.Log));
}
if (req.OptId != null)
{
predicate = predicate.And(d => d.OptId == req.OptId);
}
if (req.CreateTimeStart != DateTime.MinValue)
{
predicate = predicate.And(d => d.CreateTime >= req.CreateTimeStart);
}
if (req.CreateTimeEnd != DateTime.MinValue)
{
var CreateTimeTemp = req.CreateTimeEnd.AddDays(1);
predicate = predicate.And(d => d.CreateTime < CreateTimeTemp);
}
return predicate;
}
}
}