从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,698 @@
|
||||
using BaseOUDAL;
|
||||
using DocumentFormat.OpenXml.Office2013.Drawing.ChartStyle;
|
||||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
|
||||
using OfficeOpenXml.FormulaParsing.ExpressionGraph;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using YLErp.BLL.Eod;
|
||||
using YLErp.DBModels;
|
||||
using YLErp.Model.Enum;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 审批流程业务服务
|
||||
/// </summary>
|
||||
public class ApprovalProcessService : YLBaseService
|
||||
{
|
||||
public ApprovalProcessService(OptUserInfo optUser) : base(optUser)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加审批流程(变更或删除)
|
||||
/// </summary>
|
||||
public int AddProcess(string type, List<ApprovalProcessAddRequest> data)
|
||||
{
|
||||
var clientQuery = DataCacheProvider.GetClientDataSource().AsQueryable();
|
||||
|
||||
var delList = DbContext.approvalprocess.Where(s => s.processType == type).ToArray();
|
||||
|
||||
DbContext.approvalprocess.RemoveRange(delList);
|
||||
|
||||
if (data != null && data.Count > 0)
|
||||
{
|
||||
data = data.OrderBy(s => s.Index).ToList();
|
||||
|
||||
var list = data.Select(item => new approvalprocess
|
||||
{
|
||||
processType = item.Type,
|
||||
order = item.Index,
|
||||
roleId = item.SelectValue,
|
||||
ruleType = item.ApprovalRules,
|
||||
approvalGroupId = item.approvalGroupId,
|
||||
node = item.node,
|
||||
parentNode = item.parentNode,
|
||||
approvalCondition = item.approvalCondition
|
||||
}).ToList();
|
||||
|
||||
DbContext.approvalprocess.AddRange(list);
|
||||
}
|
||||
|
||||
if (type == "OpenProcess")
|
||||
{
|
||||
List<string> optTypes = new List<string>() { "提交开户审批", "重新提交开户审批" };
|
||||
var clients = GetClients(optTypes);
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
if (clients != null && clients.Count > 0)
|
||||
{
|
||||
throw new ServiceException("有用户在审批中,不能删除审批流程!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeClientProcess(data, clients, delList);
|
||||
}
|
||||
}
|
||||
else if (type == "TradeProcess")
|
||||
{
|
||||
|
||||
if (data != null && data.Count > 0)
|
||||
{
|
||||
ChangeTradeProcess(data, delList);
|
||||
}
|
||||
else
|
||||
{
|
||||
var trade = DbContext.trade.Where(x => x.ValidState == "Valid" && (x.TradeStatus == ConsTrade.审批中 || x.TradeStatus == ConsTrade.平仓待复核 || x.TradeStatus == ConsTrade.行权待复核 || x.TradeStatus == ConsTrade.互换待复核)).ToList();
|
||||
if (trade != null && trade.Count > 0)
|
||||
{
|
||||
throw new ServiceException("有交易在审批中,不能删除审批流程!");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == "CreditProcess")
|
||||
{
|
||||
if (data != null && data.Count == 0)
|
||||
{
|
||||
var credit = DbContext.credit.Where(x => x.ProcessOrderId > 1).ToList();
|
||||
credit.ForEach(x => x.ProcessOrderId = 1);
|
||||
var clientdb = DbContextFactory.GetClientDbContext(OptUser);
|
||||
var clientrating = clientdb.Client_Rating.Where(x => !x.IsDeleted && x.ProcessOrderId > 1).ToList();
|
||||
clientrating.ForEach(x => x.ProcessOrderId = 1);
|
||||
clientdb.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
var credit = DbContext.credit.Where(x => x.ProcessStatus == "审批中").ToList();
|
||||
if (credit != null && credit.Count > 0)
|
||||
{
|
||||
throw new ServiceException("有授信在审批中,不能删除审批流程!");
|
||||
}
|
||||
|
||||
var clientrating = DbContextFactory.GetClientDbContext(OptUser).Client_Rating.Where(x => !x.IsDeleted && x.ProcessStatus == "审批中").ToList();
|
||||
if (clientrating != null && clientrating.Count > 0)
|
||||
{
|
||||
throw new ServiceException("有资信评级在审批中,不能删除审批流程!");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == "OutCashProcess")
|
||||
{
|
||||
var clientCashs = DbContext.ClientCashInCashOut.Where(x => x.State == "审批中").ToList();
|
||||
if (clientCashs != null && clientCashs.Count > 0)
|
||||
{
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
throw new ServiceException("有资金在审批中,不能删除审批流程!");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ServiceException("有资金在审批中,不能修改审批流程!");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == "ClientProcess")
|
||||
{
|
||||
List<string> optTypes = new List<string>() { "提交信息变更审批" };
|
||||
var clients = GetClients(optTypes);
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
if (clients != null && clients.Count > 0)
|
||||
{
|
||||
throw new ServiceException("有用户在审批中,不能删除审批流程!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeClientProcess(data, clients, delList);
|
||||
}
|
||||
}
|
||||
return DbContext.SaveChanges();
|
||||
}
|
||||
#region 交易审批流程 私有方法
|
||||
/// <summary>
|
||||
/// 交易审批流程
|
||||
/// </summary>
|
||||
/// <param name="data">待保存数据</param>
|
||||
/// <param name="delList">旧数据</param>
|
||||
/// <param name="branchNode">分支节点</param>
|
||||
/// <param name="processOrderId">节点</param>
|
||||
/// <exception cref="ServiceException"></exception>
|
||||
/// <exception cref="Exception"></exception>
|
||||
private void ChangeTradeProcess(List<ApprovalProcessAddRequest> data, approvalprocess[] delList)
|
||||
{
|
||||
var trades = DbContext.trade.Where(x => x.ValidState == "Valid" && (x.TradeStatus == ConsTrade.审批中 || x.TradeStatus == ConsTrade.平仓待复核 || x.TradeStatus == ConsTrade.行权待复核 || x.TradeStatus == ConsTrade.互换待复核)).ToList();
|
||||
var noGroupData = data.Where(x => x.approvalGroupId == 0);
|
||||
var branch = data.Where(x => x.approvalGroupId != 0);//修改有分支
|
||||
var groupId = UserBLL.GetApprovalProcessGroup(UserInfo.UserId);
|
||||
var oldBranch = delList.Where(x => x.approvalGroupId != 0);//旧流程有分支
|
||||
bool NotChange = false;//不允许修改
|
||||
if (oldBranch.Count() == 0 && branch.Count() > 0)//旧流程无分支,新流程有分支
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
if (oldBranch.Count() > 0 && branch.Count() == 0)//旧流程有分支,新流程无分支
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
if (NotChange)
|
||||
{
|
||||
if (trades != null && trades.Count > 0)
|
||||
{
|
||||
throw new ServiceException("有交易在审批中,不能修改审批流程!");
|
||||
}
|
||||
}
|
||||
|
||||
if (branch.Count() > 0)//有分支情况
|
||||
{
|
||||
if (groupId == 0)
|
||||
{
|
||||
throw new Exception("该申请人不符合任何条件分支");
|
||||
}
|
||||
TradeProcessHasChange(data, delList, trades, groupId);
|
||||
|
||||
}
|
||||
else //无分支情况直接修改
|
||||
{
|
||||
UpdateTradeAudit(ProcessTradeLog.审批中, 0);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 回到审批初始节点
|
||||
/// </summary>
|
||||
/// <param name="processOrderId"></param>
|
||||
/// <param name="branchNode"></param>
|
||||
private void UpdateTradeAudit(int processOrderId, int oldBranchNode, bool all = false)
|
||||
{
|
||||
Expression<Func<trade, bool>> expression = x => x.ProcessOrderId >= ProcessTradeLog.审批中;
|
||||
if (!all)
|
||||
{
|
||||
expression = expression.And(x => x.ProcessOrderBranch == oldBranchNode);
|
||||
}
|
||||
var trades = DbContext.trade.Where(expression).ToList();
|
||||
trades.ForEach(x =>
|
||||
{
|
||||
x.ProcessOrderId = processOrderId;
|
||||
x.CheckStatus = 0;
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 有分支情况有修改
|
||||
/// </summary>
|
||||
/// <param name="data">新数据</param>
|
||||
/// <param name="delList">旧数据</param>
|
||||
/// <param name="trades">交易数据</param>
|
||||
/// <returns></returns>
|
||||
private void TradeProcessHasChange(List<ApprovalProcessAddRequest> data, approvalprocess[] delList, List<trade> trades, int groupId)
|
||||
{
|
||||
|
||||
var processOrderId = data.Min(s => s.Index);
|
||||
var branchData = data.Where(x => x.approvalGroupId != 0);//修改有分支
|
||||
var approvalConditionFirst = branchData.FirstOrDefault(x => x.approvalGroupId == groupId && x.approvalCondition == 1);//属于某个审批组
|
||||
var approvalConditionSecend = branchData.FirstOrDefault(x => x.approvalGroupId != groupId && x.approvalCondition == 2);//不属于某个审批组
|
||||
var approvalProcess = approvalConditionFirst == null ? approvalConditionSecend : approvalConditionFirst;
|
||||
if (approvalProcess == null)
|
||||
{
|
||||
throw new Exception("该申请人不符合任何条件分支");
|
||||
}
|
||||
var branchNode = approvalProcess.node;
|
||||
var branch = branchData.First();//分支节点所在位置
|
||||
var dataIds = data.Where(x => x.id != 0).Select(s => s.id).ToList();
|
||||
var changeNodeIndexs = ProcessChangeIndex(data, delList);
|
||||
bool NotChange = false;//不允许修改
|
||||
var firstBranchTrades = trades.Where(x => x.ProcessOrderBranch == 1).ToList();
|
||||
var secondBranchTrades = trades.Where(x => x.ProcessOrderBranch == 2).ToList();
|
||||
if (branch.Index == processOrderId)//跳过审批组流程
|
||||
{
|
||||
processOrderId = processOrderId + 1;
|
||||
}
|
||||
//判断数据是否有变更
|
||||
if (changeNodeIndexs.Count > 0)
|
||||
{
|
||||
var firstChange = changeNodeIndexs.Any(x => x.node == 1);//分支1有修改
|
||||
var secondChange = changeNodeIndexs.Any(x => x.node == 2);//分支2有修改
|
||||
var main = data.Any(x => x.node == 0);//新流程有主干
|
||||
var mainChange = changeNodeIndexs.Any(x => x.node == 0);//有主节点修改-包括新增&删除
|
||||
if (main || mainChange)
|
||||
{
|
||||
if (firstChange || secondChange)// 分支不可修改
|
||||
{
|
||||
if (trades.Count > 0)//有交易审批,不允许修改
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mainChange && trades.Count > 0) //主节点修改回到初始
|
||||
{
|
||||
UpdateTradeAudit(processOrderId, 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (firstChange && secondChange)//分支1,2有修改
|
||||
{
|
||||
if (trades.Count > 0)//有交易审批,不允许修改
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
}
|
||||
else if (firstChange && !secondChange)//只修改了分支1
|
||||
{
|
||||
if (firstBranchTrades.Count > 0)
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
|
||||
}
|
||||
else if (!firstChange && secondChange)//只修改了分支2
|
||||
{
|
||||
if (secondBranchTrades.Count > 0)
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NotChange)
|
||||
{
|
||||
throw new ServiceException("有交易在审批中,不能修改审批流程!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取数据修改节点集合
|
||||
/// </summary>
|
||||
/// <param name="data">新数据</param>
|
||||
/// <param name="oldList">旧数据</param>
|
||||
/// <returns></returns>
|
||||
private List<ApprovalProcessNode> ProcessChangeIndex(List<ApprovalProcessAddRequest> data, approvalprocess[] oldList)
|
||||
{
|
||||
List<ApprovalProcessNode> indexList = new List<ApprovalProcessNode>();
|
||||
foreach (var item in oldList)//筛选删除的节点
|
||||
{
|
||||
ApprovalProcessNode upNode = new ApprovalProcessNode();
|
||||
var addNode = data.FirstOrDefault(x => x.id == item.id);
|
||||
if (addNode == null)
|
||||
{
|
||||
upNode.node = item.node ?? 0;
|
||||
upNode.Index = item.order;
|
||||
indexList.Add(upNode);
|
||||
}
|
||||
}
|
||||
foreach (ApprovalProcessAddRequest item in data)//筛选新增及修改节点
|
||||
{
|
||||
ApprovalProcessNode upNode = new ApprovalProcessNode();
|
||||
if (item.id == 0)
|
||||
{
|
||||
upNode.node = item.node;
|
||||
upNode.Index = item.Index;
|
||||
indexList.Add(upNode);
|
||||
}
|
||||
var oldData = oldList.FirstOrDefault(x => x.id == item.id);
|
||||
if (oldData != null)
|
||||
{
|
||||
if (item.approvalGroupId != oldData.approvalGroupId
|
||||
|| item.approvalCondition != oldData.approvalCondition
|
||||
|| item.ApprovalRules != oldData.ruleType
|
||||
|| item.SelectValue != oldData.roleId)
|
||||
{
|
||||
upNode.node = item.node;
|
||||
upNode.Index = item.Index;
|
||||
indexList.Add(upNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
return indexList;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region 客户开户&客户信息
|
||||
/// <summary>
|
||||
/// 开户审批流程
|
||||
/// </summary>
|
||||
/// <param name="data">待保存数据</param>
|
||||
/// <param name="delList">旧数据</param>
|
||||
/// <param name="branchNode">分支节点</param>
|
||||
/// <param name="processOrderId">节点</param>
|
||||
/// <exception cref="ServiceException"></exception>
|
||||
/// <exception cref="Exception"></exception>
|
||||
private void ChangeClientProcess(List<ApprovalProcessAddRequest> data, List<Client> clients, approvalprocess[] delList)
|
||||
{
|
||||
var noGroupData = data.Where(x => x.approvalGroupId == 0);
|
||||
var branch = data.Where(x => x.approvalGroupId != 0);//修改有分支
|
||||
var groupId = UserBLL.GetApprovalProcessGroup(UserInfo.UserId);
|
||||
var oldBranch = delList.Where(x => x.approvalGroupId != 0);//旧流程有分支
|
||||
bool NotChange = false;//不允许修改
|
||||
if (oldBranch.Count() == 0 && branch.Count() > 0)//旧流程无分支,新流程有分支
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
if (oldBranch.Count() > 0 && branch.Count() == 0)//旧流程有分支,新流程无分支
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
if (NotChange)
|
||||
{
|
||||
if (clients != null && clients.Count > 0)
|
||||
{
|
||||
throw new ServiceException("有用户在审批中,不能更改审批流程!");
|
||||
}
|
||||
}
|
||||
|
||||
if (branch.Count() > 0)//有分支情况
|
||||
{
|
||||
if (groupId == 0)
|
||||
{
|
||||
throw new Exception("该申请人不符合任何条件分支");
|
||||
}
|
||||
ClientProcessHasChange(data, delList, clients, groupId);
|
||||
}
|
||||
else //无分支情况直接修改
|
||||
{
|
||||
UpdateClientAudit(ProcessTradeLog.审批中, 0, clients);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 回到审批初始节点
|
||||
/// </summary>
|
||||
/// <param name="processOrderId"></param>
|
||||
/// <param name="branchNode"></param>
|
||||
private void UpdateClientAudit(int processOrderId, int oldBranchNode, List<Client> clients, bool all = false)
|
||||
{
|
||||
var clientdb = DbContextFactory.GetClientDbContext(OptUser);
|
||||
if (!all)
|
||||
{
|
||||
clients = clients.Where(x => x.ProcessOrderBranch == oldBranchNode).ToList();
|
||||
}
|
||||
var cids = clients.Select(x => x.id).ToList();
|
||||
var range = clientdb.client_file_audit.Where(x => cids.Contains(x.ClientId)).ToList();
|
||||
clientdb.client_file_audit.RemoveRange(range);
|
||||
for (int i = 0; i < clients.Count; i++)
|
||||
{
|
||||
Client c = clientdb.client.Find(clients[i].id);
|
||||
c.ApprovalOrderId = processOrderId;
|
||||
}
|
||||
clientdb.SaveChanges();
|
||||
}
|
||||
private List<Client> GetClients(List<string> optTypes)
|
||||
{
|
||||
var clientQuery = DataCacheProvider.GetClientDataSource().AsQueryable().Where(x => x.ApprovalOrderId >= ProcessTradeLog.审批中).ToList();
|
||||
var clientdb = DbContextFactory.GetClientDbContext(OptUser);
|
||||
var clientQuerys = from c in clientQuery
|
||||
join audit in clientdb.ClientAuditLog.Where(x => optTypes.Contains(x.OptType)) on c.ApprovalLogId equals audit.id
|
||||
select c;
|
||||
var clients = clientQuerys.ToList();
|
||||
return clients;
|
||||
}
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 有分支情况有修改
|
||||
/// </summary>
|
||||
/// <param name="data">新数据</param>
|
||||
/// <param name="delList">旧数据</param>
|
||||
/// <param name="trades">交易数据</param>
|
||||
/// <returns></returns>
|
||||
private void ClientProcessHasChange(List<ApprovalProcessAddRequest> data, approvalprocess[] delList, List<Client> clients, int groupId)
|
||||
{
|
||||
var processOrderId = data.Min(s => s.Index);
|
||||
var branchData = data.Where(x => x.approvalGroupId != 0);//修改有分支
|
||||
var approvalConditionFirst = branchData.FirstOrDefault(x => x.approvalGroupId == groupId && x.approvalCondition == 1);//属于某个审批组
|
||||
var approvalConditionSecend = branchData.FirstOrDefault(x => x.approvalGroupId != groupId && x.approvalCondition == 2);//不属于某个审批组
|
||||
var approvalProcess = approvalConditionFirst == null ? approvalConditionSecend : approvalConditionFirst;
|
||||
if (approvalProcess == null)
|
||||
{
|
||||
throw new Exception("该申请人不符合任何条件分支");
|
||||
}
|
||||
var branchNode = approvalProcess.node;
|
||||
var branch = branchData.First();//分支节点所在位置
|
||||
var dataIds = data.Where(x => x.id != 0).Select(s => s.id).ToList();
|
||||
var changeNodeIndexs = ProcessChangeIndex(data, delList);
|
||||
bool NotChange = false;//不允许修改
|
||||
var firstBranchClients = clients.Where(x => x.ProcessOrderBranch == 1).ToList();
|
||||
var secondBranchClients = clients.Where(x => x.ProcessOrderBranch == 2).ToList();
|
||||
if (branch.Index == processOrderId)//跳过审批组流程
|
||||
{
|
||||
processOrderId = processOrderId + 1;
|
||||
}
|
||||
//判断数据是否有变更
|
||||
if (changeNodeIndexs.Count > 0)
|
||||
{
|
||||
var firstChange = changeNodeIndexs.Any(x => x.node == 1);//分支1有修改
|
||||
var secondChange = changeNodeIndexs.Any(x => x.node == 2);//分支2有修改
|
||||
var main = data.Any(x => x.node == 0);//新流程有主干
|
||||
var mainChange = changeNodeIndexs.Any(x => x.node == 0);//有主节点修改-包括新增&删除
|
||||
if (main || mainChange)
|
||||
{
|
||||
if (firstChange|| secondChange)// 分支不可修改
|
||||
{
|
||||
if (clients.Count > 0)//有交易审批,不允许修改
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mainChange&& clients.Count > 0) //主节点修改回到初始
|
||||
{
|
||||
UpdateClientAudit(processOrderId, 0, clients, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (firstChange && secondChange)//分支1,2有修改
|
||||
{
|
||||
if (clients.Count > 0)//有交易审批,不允许修改
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
}
|
||||
else if (firstChange && !secondChange)//只修改了分支1
|
||||
{
|
||||
if (firstBranchClients.Count > 0)
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
|
||||
}
|
||||
else if (!firstChange && secondChange)//只修改了分支2
|
||||
{
|
||||
if (secondBranchClients.Count > 0)
|
||||
{
|
||||
NotChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NotChange)
|
||||
{
|
||||
throw new ServiceException("有用户在审批中,不能修改审批流程!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 投资规模审核
|
||||
/// </summary>
|
||||
public bool CheckTradeScale(trade trade)
|
||||
{
|
||||
var orderId = trade.ProcessOrderId;
|
||||
var um = DataCacheModule.DataCacheManager.GetUnderlyingDataSource().GetData(trade.UnderlyingId);
|
||||
if (um == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//2021/06/23 规模审批使用deltaCash
|
||||
var UsedScale = 0.0;
|
||||
// 如果是审批组
|
||||
var tradeProcess = TradeProcess();
|
||||
var orderIdCount = tradeProcess.Where(x => x.order == trade.ProcessOrderId);//判断是否有分支
|
||||
int orderNode = orderIdCount.Count() > 1 ? trade.ProcessOrderBranch : 0;
|
||||
if (orderIdCount.Count() == 1)
|
||||
{
|
||||
orderNode = orderIdCount.First().node ?? 0;
|
||||
}
|
||||
var roleId = tradeProcess.OrderBy(o => o.order).FirstOrDefault(o => o.order == orderId && o.node == orderNode && o.processType == "TradeProcess").roleId;
|
||||
var approvalGrade = DbContext.approvalGrade.FirstOrDefault(o => o.RoleId == roleId && o.AssetId == trade.AssetId && o.Rule == RuleEnum.投资规模);
|
||||
List<trade> trades;
|
||||
var underlyingPrice = DataCacheProvider.GetUnderlyingDataSource();
|
||||
|
||||
trades = (from t in DbContext.trade
|
||||
join u in DbContext.underlying_manager
|
||||
on t.UnderlyingId equals u.id
|
||||
where t.AssetId == trade.AssetId
|
||||
&& t.TradeType != "结构化交易"
|
||||
&& ConsTrade.PositionTradeStatusList.Contains(t.TradeStatus)
|
||||
&& !ConsTrade.TradeTypesForHedge.Contains(t.TradeType)
|
||||
&& t.ValidState != "InValid"
|
||||
select t).ToList();
|
||||
trades.Add(trade);
|
||||
BLL.tradeBLL.SetFieldsByTradeType(trade);
|
||||
if (trades != null && trades.Count > 0)
|
||||
{
|
||||
var riskList = RealtimePnlCalc.RealTimeRiskCalc(SystemValueDate, trades, underlyingPrice, new List<string> { "持仓" }, false, QdpModule.QdpPricingRequest.BASIC_PRICING);
|
||||
UsedScale += riskList.Sum(o => (o.DeltaCash ?? 0));
|
||||
}
|
||||
if (approvalGrade != null)
|
||||
{
|
||||
return UsedScale <= (approvalGrade.DeltaCashScale ?? 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CheckTradeScale(int enid)
|
||||
{
|
||||
var trade = DbContext.trade.FirstOrDefault(o => o.id == enid);
|
||||
if (trade != null)
|
||||
{
|
||||
return CheckTradeScale(trade);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ServiceException("未找到交易");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 仅审批投资规模的步骤
|
||||
/// </summary>
|
||||
/// <param name="trade"></param>
|
||||
/// <returns>-2:该步骤存在字段审核没审核或者没有规模审核 -1:规模审核未过 0:审核直接通过 1:规模审核通过,之后的流程中存在字段审核</returns>
|
||||
public int CheckTradeApprovalStep(trade trade, int userId, bool hadCheckParam = false)
|
||||
{
|
||||
var roles = UserBLL.GetRolesByUserId(userId).Select(o => o.Id);
|
||||
var groupId = UserBLL.GetApprovalProcessGroup(userId);
|
||||
var tradeProcess = TradeProcess();
|
||||
bool approvalBranch = tradeProcess.Any(x => x.approvalGroupId != 0);//审批流程有分支情况
|
||||
trade.ProcessOrderBranch = 0;
|
||||
if (trade.ProcessOrderId <= 0)
|
||||
{
|
||||
if (approvalBranch)//审批流程有分支情况
|
||||
{
|
||||
//该审批组属于流程的审批组或该审批组不属于流程审批组
|
||||
var tradeProessBranchQuery = tradeProcess.FirstOrDefault(x => (x.approvalGroupId == groupId && x.approvalCondition == 1) || (x.approvalGroupId != groupId && x.approvalCondition == 2));
|
||||
if (tradeProessBranchQuery == null)//都没有情况
|
||||
{
|
||||
return -3;
|
||||
}
|
||||
trade.ProcessOrderId = ProcessTradeLog.审批中;
|
||||
|
||||
if (trade.ProcessOrderId >= tradeProessBranchQuery.order)
|
||||
{
|
||||
trade.ProcessOrderId = tradeProessBranchQuery.order + 1;//跳过审批组那一级
|
||||
}
|
||||
trade.ProcessOrderBranch = tradeProessBranchQuery.node ?? 1;//审批组分子
|
||||
if (!tradeProcess.Any(x => x.order >= trade.ProcessOrderId && (x.node == trade.ProcessOrderBranch || x.node == 0)))//分支无需审批,直接通过
|
||||
{
|
||||
trade.ProcessOrderId = ProcessTradeLog.审批通过;
|
||||
trade.CheckTradeUpdate = Convert.ToInt32(TradeCheckEnum.StatusOfNew);
|
||||
trade.ProcessOptDate = DateTime.Now;
|
||||
trade.ProcessStatus = ProcessTradeStatus.通过审批.ToString();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
trade.ProcessOrderId = ProcessTradeLog.审批中;
|
||||
}
|
||||
}
|
||||
// 如果是审批组
|
||||
var orderIdCount = tradeProcess.Where(x => x.order == trade.ProcessOrderId);//判断是否有分支
|
||||
int processOrderNode = orderIdCount.Count() > 1 ? trade.ProcessOrderBranch : 0;
|
||||
if (orderIdCount.Count() == 1)
|
||||
{
|
||||
processOrderNode = orderIdCount.First().node ?? 0;
|
||||
}
|
||||
var NowProcess = tradeProcess.FirstOrDefault(o => o.order == trade.ProcessOrderId && o.node == processOrderNode && roles.Contains(o.roleId));
|
||||
|
||||
trade.TradeStatus = ConsTrade.审批中;
|
||||
trade.ProcessStatus = ProcessTradeStatus.审批中.ToString();
|
||||
trade.ProcessOptDate = DateTime.Now;
|
||||
|
||||
if (NowProcess != null && NowProcess.ruleType != null && (NowProcess.ruleType == "1" || (NowProcess.ruleType.Contains("1") && hadCheckParam)))
|
||||
{
|
||||
if (CheckTradeScale(trade))
|
||||
{
|
||||
var process = tradeProcess.FirstOrDefault(o => o.ruleType != null && o.ruleType.Contains("0") && o.order > NowProcess.order && o.node == processOrderNode);
|
||||
if (process != null)
|
||||
{
|
||||
trade.ProcessOrderId = process.order;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
trade.ProcessOrderId = ProcessTradeLog.审批通过;
|
||||
trade.CheckTradeUpdate = Convert.ToInt32(TradeCheckEnum.StatusOfNew);
|
||||
trade.ProcessOptDate = DateTime.Now;
|
||||
trade.ProcessStatus = ProcessTradeStatus.通过审批.ToString();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var lastScaleProcessOrder = tradeProcess.Where(o => o.ruleType.Contains("1")).Select(o => o.order).Max();
|
||||
if (trade.ProcessOrderId >= lastScaleProcessOrder)
|
||||
{
|
||||
throw new ServiceException($"该交易'{trade.TradeNumber}'规模审批流程最后一步的审批角色对审批簿记的投资规模依然不足!");
|
||||
}
|
||||
trade.ProcessOrderId = trade.ProcessOrderId + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return -2;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取所有交易审批节点
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<approvalprocess> TradeProcess()
|
||||
{
|
||||
var tradeOrders = DbContext.approvalprocess.Where(t => t.processType == "TradeProcess").OrderBy(o => o.order).ToList();
|
||||
return tradeOrders;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加审批流程请求
|
||||
/// </summary>
|
||||
public class ApprovalProcessAddRequest
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string Type { get; set; }
|
||||
public int Index { get; set; }
|
||||
public int SelectValue { get; set; }
|
||||
public string ApprovalRules { get; set; }
|
||||
|
||||
public int approvalGroupId { get; set; }
|
||||
|
||||
public int node { get; set; }
|
||||
public int parentNode { get; set; }
|
||||
public int approvalCondition { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 审批流程修改节点
|
||||
/// </summary>
|
||||
public class ApprovalProcessNode
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public int node { get; set; }
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,632 @@
|
||||
using YieldChain.Commons;
|
||||
using YLErp.BLL;
|
||||
using YLErp.Models;
|
||||
using YLErp.Modules.AppModule;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class ClientEditConfigService
|
||||
{
|
||||
static DateTime _optDate;
|
||||
static ClientEditConfig _config;
|
||||
static readonly ValueWrap<DateTime> _updateTime;
|
||||
|
||||
static ClientEditConfigService()
|
||||
{
|
||||
_updateTime = new ValueWrap<DateTime>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置配置
|
||||
/// </summary>
|
||||
public static void ResetConfig()
|
||||
{
|
||||
lock (_updateTime)
|
||||
{
|
||||
_config = null;
|
||||
_updateTime.Value = _optDate = DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取配置json
|
||||
/// </summary>
|
||||
public static string GetConfigJson()
|
||||
{
|
||||
using (var db = DbContextFactory.GetYLDbContext())
|
||||
{
|
||||
var query = db.AppConfig.Where(n => n.PGroup == "System" && n.PName == "ClientEditConfig");
|
||||
var configJson = query.Select(n => n.PValue).FirstOrDefault();
|
||||
return configJson.TrimToNull() ?? Properties.Resources.clientEditConfig;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static ClientEditConfig GetConfig(bool forceUpdateSelects = false, bool isView = false)
|
||||
{
|
||||
string configJson = null;
|
||||
|
||||
if (_config == null || _updateTime.Value.AddSeconds(60) < DateTime.Now)
|
||||
{
|
||||
lock (_updateTime)
|
||||
{
|
||||
if (_config == null || _updateTime.Value.AddSeconds(60) < DateTime.Now)
|
||||
{
|
||||
using (var db = DbContextFactory.GetYLDbContext())
|
||||
{
|
||||
var query = db.AppConfig.Where(n => n.PGroup == "System" && n.PName == "ClientEditConfig");
|
||||
|
||||
if (_config == null || query.Select(n => (DateTime?)n.OptDate).FirstOrDefault() != _optDate)
|
||||
{
|
||||
var data = query.Select(n => new { n.PValue, n.OptDate }).FirstOrDefault();
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
_optDate = data.OptDate;
|
||||
configJson = data.PValue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(configJson))
|
||||
{
|
||||
_config = null;
|
||||
configJson = Properties.Resources.clientEditConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (configJson != null)
|
||||
{
|
||||
var index = configJson.IndexOf('=');
|
||||
if (index > 0)
|
||||
{
|
||||
configJson = configJson.Substring(index + 1);
|
||||
}
|
||||
|
||||
_updateTime.Value = DateTime.MinValue;
|
||||
|
||||
_config = JsonHelper.Deserialize<ClientEditConfig>(configJson) ?? new ClientEditConfig();
|
||||
//开户管理和客户列表列去重;
|
||||
_config.openList = _config.openList.DistinctBy(O => O.name);
|
||||
_config.clientList = _config.clientList.DistinctBy(O => O.name);
|
||||
}
|
||||
else if (_config == null)
|
||||
{
|
||||
throw new SystemException("系统错误");
|
||||
}
|
||||
else if (!forceUpdateSelects)
|
||||
{
|
||||
return _config.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//防止服务器时间更改所以需要双重验证(比如服务器时间由15点改为12点)
|
||||
if (forceUpdateSelects || _updateTime.Value > DateTime.Now || _updateTime.Value.AddMinutes(1) < DateTime.Now)
|
||||
{
|
||||
lock (_updateTime)
|
||||
{
|
||||
if (forceUpdateSelects || _updateTime.Value > DateTime.Now || _updateTime.Value.AddMinutes(1) < DateTime.Now)
|
||||
{
|
||||
var allFields = _config.sections.SelectMany(n => n.fields ?? Enumerable.Empty<FormEditField>()).ToArray();
|
||||
foreach (var f in allFields)
|
||||
{
|
||||
if (f.name != null && f.name.StartsWith("meta.", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
f.name = "meta_" + f.name.Substring(5);
|
||||
}
|
||||
}
|
||||
var fieldNames = allFields.Select(m => m.name ?? string.Empty).ToHashSet();
|
||||
|
||||
//客户等级
|
||||
_config.selects[nameof(Client.LevelId)] = ClientDataModelV1.GetAllclientlevel();
|
||||
|
||||
//客户等级
|
||||
_config.selects[nameof(Client.SettlementCurrency)] = ClientDataModelV1.GetAllCurrency();
|
||||
|
||||
//客服经理
|
||||
if (fieldNames.Contains(nameof(Client.CustomerManagerId)))
|
||||
{
|
||||
_config.selects[nameof(Client.CustomerManagerId)] = ClientDataModelV1.GetAllCustomerManager();
|
||||
}
|
||||
|
||||
//销售
|
||||
if (fieldNames.Contains(nameof(Client.Seller)))
|
||||
{
|
||||
_config.selects[nameof(Client.Seller)] = SalesDataModelV1.GetSalesmen();
|
||||
}
|
||||
|
||||
//所属机构
|
||||
if (fieldNames.Contains(nameof(Client.ParentId)))
|
||||
{
|
||||
_config.selects[nameof(Client.ParentId)] = ClientDataModelV1.GetAllOpenaccountClient(null);
|
||||
}
|
||||
|
||||
//归属营业部
|
||||
if (fieldNames.Contains(nameof(Client.SalesDepartmentId)))
|
||||
{
|
||||
_config.selects[nameof(Client.SalesDepartmentId)] = SalesDataModelV1.GetAllSaleDepartment();
|
||||
}
|
||||
|
||||
//交易种类
|
||||
if (!_config.selects.ContainsKey(nameof(Client.DerivativesInvestmentVarieties)))
|
||||
{
|
||||
_config.selects[nameof(Client.DerivativesInvestmentVarieties)] = ClientDataModelV1.GetAllDerivativesInvestmentVarieties();
|
||||
}
|
||||
|
||||
//不良诚信记录
|
||||
if (!_config.selects.ContainsKey(nameof(Client.BadFaithRecord)))
|
||||
{
|
||||
_config.selects[nameof(Client.BadFaithRecord)] = ClientDataModelV1.GetAllBadFaithRecord();
|
||||
}
|
||||
|
||||
//可接受风险服务
|
||||
_config.selects[nameof(Client.RiskServiceDegree)] = ClientDataModelV1.GetRiskServiceDegree();
|
||||
|
||||
//适当性评估人
|
||||
_config.selects[nameof(Client.AppropriatenessAssessor)] = ClientDataModelV1.GetAppropriatenessAssessor(!isView);
|
||||
|
||||
//适当性评级-默认值,如果配置了其他项,这里的设置会被覆盖掉
|
||||
_config.selects[nameof(Client.AppropriatenessDegree)] = ClientDataModelV1.GetAppropriatenessList();
|
||||
|
||||
var dicInfos =
|
||||
_config.sections
|
||||
.Where(n => n.fields != null)
|
||||
.SelectMany(n =>
|
||||
n.fields.Where(m => m.dictionaryKey != null && m.dictionaryKey != "")
|
||||
.Select(m => new KeyValuePair<string, string>(m.name, m.dictionaryKey ?? string.Empty)))
|
||||
.Concat(new[] {
|
||||
new KeyValuePair<string, string>("文件类型", "文件类型"),
|
||||
new KeyValuePair<string, string>("权益类签署版本", "权益类签署版本"),
|
||||
new KeyValuePair<string, string>("资金用途", "资金用途"),
|
||||
}).ToArray();
|
||||
|
||||
var yldic = DictionaryBLL.GetDictionary(dicInfos.Select(O => O.Value).ToArray());
|
||||
|
||||
foreach (var item in dicInfos)
|
||||
{
|
||||
if (item.Key == nameof(Client.AppropriatenessDegree)) { continue; }
|
||||
_config.selects[item.Key] = yldic.GetList(item.Value, false);
|
||||
//行业字段比较特殊,KeyValue需要保持一致;
|
||||
if (item.Key == nameof(Client.BusinessType) || item.Key == nameof(Client.ProtocolSignVersion))
|
||||
{
|
||||
_config.selects[item.Key].ToList().ForEach(O =>
|
||||
{
|
||||
O.Value = O.Text;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_updateTime.Value = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _config.Clone();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前配置的所有表单字段
|
||||
/// </summary>
|
||||
public static IEnumerable<FormEditField> GetAllFormEditField()
|
||||
{
|
||||
var config = GetConfig(false);
|
||||
return config.sections.SelectMany(n => n.fields ?? Enumerable.Empty<FormEditField>());
|
||||
}
|
||||
|
||||
public static IEnumerable<FormEditField> GetAllFormEditFieldByTableId(string tableid)
|
||||
{
|
||||
var config = GetConfig(false);
|
||||
return config.sections.Where(l => l.tabId == tableid).SelectMany(n => n.fields ?? Enumerable.Empty<FormEditField>());
|
||||
}
|
||||
|
||||
public static string GetSelectValue(string name, string text)
|
||||
{
|
||||
var config = GetConfig(true);
|
||||
var selectItem = _config.selects.Where(a => a.Key == name).FirstOrDefault();
|
||||
var item = selectItem.Value.Where(a => a.Text == text).FirstOrDefault();
|
||||
return item != null ? item.Value : string.Empty;
|
||||
}
|
||||
|
||||
public static FormEditField GetFormEditFieldByName(string name)
|
||||
{
|
||||
var FormEditFields = GetAllFormEditField();
|
||||
if (FormEditFields != null)
|
||||
{
|
||||
return FormEditFields.Where(a => a.name == name).FirstOrDefault();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FormEditField GetFormEditFieldByLabel(string label)
|
||||
{
|
||||
var config = GetConfig(true);
|
||||
var FormEditFields = GetAllFormEditField();
|
||||
if (FormEditFields != null)
|
||||
{
|
||||
return FormEditFields.Where(a => a.label == label).FirstOrDefault();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FormEditField GetFormEditFieldByLabel(IEnumerable<FormEditField> FormEditFields,string label)
|
||||
{
|
||||
if (FormEditFields != null)
|
||||
{
|
||||
return FormEditFields.Where(a => a.label == label).FirstOrDefault();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换成横向流布局的字段列表
|
||||
/// </summary>
|
||||
public static IEnumerable<FormEditField> GetFlatList(IEnumerable<FormEditField> fields, out int cols)
|
||||
{
|
||||
cols = 0;
|
||||
|
||||
if (fields is null)
|
||||
{
|
||||
return Enumerable.Empty<FormEditField>();
|
||||
}
|
||||
|
||||
var colIndex = 0;
|
||||
var list = new List<FormEditField>();
|
||||
var listList = new List<List<FormEditField>> { list };
|
||||
|
||||
foreach (var f in fields)
|
||||
{
|
||||
if (f.type == "new-col")
|
||||
{
|
||||
if (list.Count > 0)
|
||||
{
|
||||
colIndex++;
|
||||
if (colIndex >= listList.Count)
|
||||
{
|
||||
listList.Add(list = new List<FormEditField>());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (f.type == "new-row")
|
||||
{
|
||||
colIndex = 0;
|
||||
JustifyListList(listList);
|
||||
list = listList[0];
|
||||
}
|
||||
else if (f.visible)
|
||||
{
|
||||
if (f.layout == "row")
|
||||
{
|
||||
JustifyListList(listList);
|
||||
listList.ForEach(x => x.Add(f));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var len = JustifyListList(listList);
|
||||
|
||||
var results = new List<FormEditField>(fields.Count());
|
||||
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
results.AddRange(listList.Select(n => n[i]));
|
||||
}
|
||||
|
||||
cols = listList.Count;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private static int JustifyListList(List<List<FormEditField>> listList)
|
||||
{
|
||||
if (listList.Count > 0)
|
||||
{
|
||||
var maxCount = listList.Max(n => n.Count);
|
||||
foreach (var list in listList)
|
||||
{
|
||||
if (list.Count < maxCount)
|
||||
{
|
||||
list.AddRange(new FormEditField[maxCount - list.Count]);
|
||||
}
|
||||
}
|
||||
return maxCount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认配置内容
|
||||
/// </summary>
|
||||
public static string GetDefaultConfigJson()
|
||||
{
|
||||
return Properties.Resources.clientEditConfig;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前配置内容
|
||||
/// </summary>
|
||||
public static string GetCurrentConfigJson()
|
||||
{
|
||||
using (var db = DbContextFactory.GetYLDbContext())
|
||||
{
|
||||
return db.AppConfig.Where(n => n.PGroup == "System" && n.PName == "ClientEditConfig")
|
||||
.Select(n => n.PValue).FirstOrDefault().TrimToNull() ?? Properties.Resources.clientEditConfig;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存配置
|
||||
/// </summary>
|
||||
public static void SaveEditConfig(string config)
|
||||
{
|
||||
var arr = config.Split('=');
|
||||
if (arr.Length == 2)
|
||||
{
|
||||
var obj = JsonHelper.Deserialize<ClientEditConfig>(arr[1]);
|
||||
if (obj?.clientList?.Any() ?? false)
|
||||
{
|
||||
var nameList = obj.clientList.GroupBy(O => O.name).Where(O => O.ToArray().Length > 1).Select(O => O.Key);
|
||||
if (nameList.Any())
|
||||
{
|
||||
throw new ServiceException("客户列表中出现列name信息重复,name为" + string.Join(",", nameList));
|
||||
}
|
||||
}
|
||||
if (obj?.openList?.Any() ?? false)
|
||||
{
|
||||
var nameList = obj.openList.GroupBy(O => O.name).Where(O => O.ToArray().Length > 1).Select(O => O.Key);
|
||||
if (nameList.Any())
|
||||
{
|
||||
throw new ServiceException("开户列表中出现列name信息重复,name为" + string.Join(",", nameList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new AppConfigService(OptUserInfo.SystemUser).SaveConfig("System", "ClientEditConfig", config, "string", "");
|
||||
|
||||
ResetConfig();
|
||||
}
|
||||
|
||||
public static List<ClientField> GetOpenList()
|
||||
{
|
||||
var config = GetConfig();
|
||||
return config.openList.ToList();
|
||||
}
|
||||
|
||||
public static List<ClientField> GetClientList()
|
||||
{
|
||||
var config = GetConfig();
|
||||
return config.clientList.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 客户编辑配置
|
||||
/// </summary>
|
||||
public class ClientEditConfig
|
||||
{
|
||||
private IEnumerable<FormEditSection> _sections;
|
||||
private Dictionary<string, IEnumerable<SelectItem>> _selectItems;
|
||||
private Dictionary<string, string> _defaults;
|
||||
private Dictionary<string, IEnumerable<object>> _listDatas;
|
||||
private IEnumerable<ClientField> _openList;
|
||||
private IEnumerable<ClientField> _clientList;
|
||||
|
||||
/// <summary>
|
||||
/// 页面编辑数据组
|
||||
/// </summary>
|
||||
public IEnumerable<FormEditSection> sections
|
||||
{
|
||||
get => _sections ?? (_sections = Enumerable.Empty<FormEditSection>());
|
||||
set => _sections = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 页面编辑下拉选择数据
|
||||
/// </summary>
|
||||
public Dictionary<string, IEnumerable<SelectItem>> selects
|
||||
{
|
||||
get => _selectItems ?? (_selectItems = new Dictionary<string, IEnumerable<SelectItem>>());
|
||||
set => _selectItems = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 页面编辑数据默认值
|
||||
/// </summary>
|
||||
public Dictionary<string, string> defaults
|
||||
{
|
||||
get => _defaults ?? (_defaults = new Dictionary<string, string>());
|
||||
set => _defaults = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 页面编辑列表数据
|
||||
/// </summary>
|
||||
public Dictionary<string, IEnumerable<object>> lists
|
||||
{
|
||||
get => _listDatas ?? (_listDatas = new Dictionary<string, IEnumerable<object>>());
|
||||
set => _listDatas = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// 开户编辑列表数据
|
||||
/// </summary>
|
||||
public IEnumerable<ClientField> openList
|
||||
{
|
||||
get => _openList ?? (_openList = Enumerable.Empty<ClientField>());
|
||||
set => _openList = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// 客户编辑列表数据
|
||||
/// </summary>
|
||||
public IEnumerable<ClientField> clientList
|
||||
{
|
||||
get => _clientList ?? (_clientList = Enumerable.Empty<ClientField>());
|
||||
set => _clientList = value;
|
||||
}
|
||||
|
||||
public ClientEditConfig Clone()
|
||||
{
|
||||
var clone = (ClientEditConfig)MemberwiseClone();
|
||||
|
||||
clone.lists = null;
|
||||
|
||||
if (clone.sections != null)
|
||||
{
|
||||
clone.sections = clone.sections.Select(n => n.Clone()).ToArray();
|
||||
}
|
||||
|
||||
if (clone.defaults != null)
|
||||
{
|
||||
clone.defaults = new Dictionary<string, string>(clone.defaults);
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑组
|
||||
/// </summary>
|
||||
public class FormEditSection
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否可见
|
||||
/// </summary>
|
||||
public bool visible { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// tab ID
|
||||
/// </summary>
|
||||
public string tabId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// tab标题
|
||||
/// </summary>
|
||||
public string title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 表单样式类
|
||||
/// </summary>
|
||||
public string className { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 视图路径(这个值存在时fields失效)
|
||||
/// </summary>
|
||||
public string viewPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 表单输入字段
|
||||
/// </summary>
|
||||
public IEnumerable<FormEditField> fields { get; set; }
|
||||
|
||||
public FormEditSection Clone()
|
||||
{
|
||||
var clone = (FormEditSection)MemberwiseClone();
|
||||
|
||||
if (clone.fields != null)
|
||||
{
|
||||
clone.fields = clone.fields.Select(n => n.Clone()).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
clone.fields = Enumerable.Empty<FormEditField>();
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表单字段
|
||||
/// </summary>
|
||||
public class FormEditField
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否可见
|
||||
/// </summary>
|
||||
public bool visible { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 字段名
|
||||
/// </summary>
|
||||
public string name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 字段说明
|
||||
/// </summary>
|
||||
public string label { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 字段类型(特殊:none,new-col,new-row)
|
||||
/// </summary>
|
||||
public string type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 字段样式类
|
||||
/// </summary>
|
||||
public string className { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否必需
|
||||
/// </summary>
|
||||
public bool required { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否只读
|
||||
/// </summary>
|
||||
public bool @readonly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当type等于select时是否增加空选项
|
||||
/// </summary>
|
||||
public bool appendBlank { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// placeholder
|
||||
/// </summary>
|
||||
public string placeholder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 布局
|
||||
/// </summary>
|
||||
public string layout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据字典绑定关系
|
||||
/// </summary>
|
||||
public string dictionaryKey { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{name}-{label}-{type}";
|
||||
}
|
||||
|
||||
public FormEditField Clone()
|
||||
{
|
||||
return (FormEditField)MemberwiseClone();
|
||||
}
|
||||
}
|
||||
|
||||
public class ClientField
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string label { get; set; }
|
||||
public bool hidden { get; set; }
|
||||
public bool sortable { get; set; }
|
||||
/// <summary>
|
||||
/// left, center, right.
|
||||
/// </summary>
|
||||
public string align { get; set; }
|
||||
public string width { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using BaseOUDAL;
|
||||
using NPOI.SS.UserModel;
|
||||
using YLErp.DBModels.Consts;
|
||||
using YLErp.Model;
|
||||
using YLErp.Office.ExcelModule;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
public class DividendrateRecordService : YLBaseService
|
||||
{
|
||||
public DividendrateRecordService(OptUserInfo optUser) : base(optUser)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ChangeDividendrate(dividendrate_record record)
|
||||
{
|
||||
using (var trans = BeginTransaction())
|
||||
{
|
||||
record.OptId = UserId;
|
||||
record.OptName = UserName;
|
||||
record.OptDate = DateTime.Now;
|
||||
DbContext.dividendrate_record.Add(record);
|
||||
DbContext.SaveChanges();
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SearchListResult<dividendrate_record> GetDividendrateChangeSearch(DividendrateChangereq req)
|
||||
{
|
||||
var query = DbContext.dividendrate_record.Where(x => 1 == 1);
|
||||
if (req.Ids == null || req.Ids.Count == 0)
|
||||
{
|
||||
if (req.ValueDateStart != default)
|
||||
{
|
||||
query = query.Where(a => req.ValueDateStart <= a.ValueDate);
|
||||
}
|
||||
|
||||
if (req.ValueDateEnd != default)
|
||||
{
|
||||
var endDay = req.ValueDateEnd.AddDays(1);
|
||||
query = query.Where(a => endDay > a.ValueDate);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
query = query.Where(a => req.Ids.Contains(a.id));
|
||||
}
|
||||
if (string.IsNullOrEmpty(req.sidx))
|
||||
{
|
||||
req.sidx = "ValueDate,id";
|
||||
req.sord = "desc";
|
||||
}
|
||||
var retListResult = query.ToSearchList(req);
|
||||
|
||||
return retListResult;
|
||||
}
|
||||
|
||||
public byte[] ExportClientCashChange(DividendrateChangereq req)
|
||||
{
|
||||
var searchListResult = GetDividendrateChangeSearch(req);
|
||||
var templateFile = OtcAppContext.MapPath("~/App_Docs/导出模板/变更记录模板_设置模型参数.xlsx");
|
||||
return ExcelGenerator.UseTemplateGenerator(templateFile).AddVariable(new { list = searchListResult.rows }).GenerateBytes();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using BaseOUDAL;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
//自ylerpweb项目移入
|
||||
|
||||
public class RoleRight
|
||||
{
|
||||
public static List<RoleFunction> Roles = new List<RoleFunction>();
|
||||
|
||||
public static bool GetRoleFunction(int? roleId, string fName)
|
||||
{
|
||||
using (var db = new ErpBaseContext())
|
||||
{
|
||||
Roles = (from o in db.RoleFunctions join p in db.Functions on o.FunctionId equals p.Id where o.RoleId == roleId && p.Name == fName select o).ToList();
|
||||
if (Roles != null && Roles.Count > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<SystemUser> GetSystemUserByFunction(string fName, bool checkStatus = true)
|
||||
{
|
||||
var users = new List<SystemUser>();
|
||||
using (var db = new ErpBaseContext())
|
||||
{
|
||||
if (string.IsNullOrEmpty(fName))
|
||||
{
|
||||
users = db.SystemUsers.Where(a=>a.State==0 || !checkStatus).AsQueryable().ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
users = (from a in db.SystemUsers join b in db.RoleUsers on a.Id equals b.UserId join o in db.RoleFunctions on b.RoleId equals o.RoleId join p in db.Functions on o.FunctionId equals p.Id where p.Name == fName && (a.State != 1 || !checkStatus) select a).Distinct().ToList();
|
||||
}
|
||||
return users;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetRoleFunctionByRoles(List<int> roleIds, string fName)
|
||||
{
|
||||
using (var db = new ErpBaseContext())
|
||||
{
|
||||
foreach (var ids in roleIds)
|
||||
{
|
||||
Roles = (from o in db.RoleFunctions join p in db.Functions on o.FunctionId equals p.Id where o.RoleId == ids && p.Name == fName select o).ToList();
|
||||
}
|
||||
}
|
||||
if (Roles != null && Roles.Count > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using BaseOUDAL;
|
||||
using YLErp.Models;
|
||||
using YLErp.Modules.SalesModule;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
//自ylerpweb项目移入
|
||||
|
||||
/// <summary>
|
||||
/// 销售员
|
||||
/// </summary>
|
||||
public class SalesDataModelV1
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取人员姓名
|
||||
/// </summary>
|
||||
public static List<SelectItem> GetSalesmen()
|
||||
{
|
||||
var salesmen = new SalesmenDataService(OptUserInfo.SystemUser).GetSalesmen();
|
||||
|
||||
return salesmen.Select(O => new SelectItem
|
||||
{
|
||||
Value = O.id.ToString(),
|
||||
Text = O.Name ?? string.Empty
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 所有销售
|
||||
/// </summary>
|
||||
public static List<SelectItem> GetAllSalesmen()
|
||||
{
|
||||
var result = new List<SelectItem>();
|
||||
var salesmen = new SalesmenDataService(OptUserInfo.SystemUser).GetAllSalesmen();
|
||||
result = salesmen.Select(O => new SelectItem
|
||||
{
|
||||
Text = O.Name + "",
|
||||
Value = O.id + ""
|
||||
}).ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取部门名
|
||||
/// </summary>
|
||||
public static List<SelectItem> GetDepartment()
|
||||
{
|
||||
var result = new List<SelectItem>();
|
||||
var departments = new SalesmenDataService(OptUserInfo.SystemUser).GetDepartment();
|
||||
result = departments.Select(O => new SelectItem
|
||||
{
|
||||
Text = O + "",
|
||||
Value = O + ""
|
||||
}).ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有营业部
|
||||
/// </summary>
|
||||
public static List<SelectItem> GetAllSaleDepartment()
|
||||
{
|
||||
using (var condb = new ErpBaseContext())
|
||||
{
|
||||
var list = condb.Departments.Where(x => x.DepartmentType == "营业部").ToList();
|
||||
return list.Select(m => new SelectItem
|
||||
{
|
||||
Text = m.Name ?? string.Empty,
|
||||
Value = m.Id.ToString()
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
using BaseOUDAL;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统权限数据服务
|
||||
/// </summary>
|
||||
public class SysFunctionService : BaseService<ErpBaseContext>
|
||||
{
|
||||
public SysFunctionService(OptUserInfo optUser) : base(optUser)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 来自SystemController.SyncFunctionRight
|
||||
/// </summary>
|
||||
/// <param name="functionRightXmlFilePath"></param>
|
||||
public string SyncFunctionRight(string functionRightXmlFilePath)
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
var sbMsg = new StringBuilder();
|
||||
|
||||
doc.Load(functionRightXmlFilePath);
|
||||
|
||||
var pNodes = doc.DocumentElement.ChildNodes;
|
||||
if (pNodes.Count < 1)
|
||||
{
|
||||
throw new ServiceException("error count");
|
||||
}
|
||||
|
||||
var funcDic = DbContext.Functions.ToList()
|
||||
.ToDictionary(n => n.ParentName.Trim().Trim('-') + "-" + n.Name.Trim());
|
||||
|
||||
foreach (var item in funcDic.Values)
|
||||
{
|
||||
item.Sort = -9999;
|
||||
}
|
||||
|
||||
var psort = 0;
|
||||
|
||||
foreach (XmlNode xn in pNodes)
|
||||
{
|
||||
if (xn.NodeType != XmlNodeType.Element || xn.Name != "FunctionParent")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var pxe = (XmlElement)xn;
|
||||
var parentName = pxe.GetAttribute("Name").TrimToEmpty();
|
||||
var parentNote = pxe.GetAttribute("Note").TrimToEmpty();
|
||||
var type = pxe.GetAttribute("Type").TrimToEmpty();
|
||||
var title = pxe.GetAttribute("Title").TrimToEmpty();
|
||||
if (string.IsNullOrEmpty(parentName))
|
||||
{
|
||||
throw new ServiceException("FunctionParent Name不能为空");
|
||||
}
|
||||
//父节点
|
||||
if (!funcDic.TryGetValue("-" + parentName, out var pzFunc))
|
||||
{
|
||||
//没有父节点
|
||||
var pFunc = new Function
|
||||
{
|
||||
Name = parentName,
|
||||
Note = parentNote,
|
||||
Sort = psort++,
|
||||
Type = type,
|
||||
ParentName = "-"
|
||||
};
|
||||
DbContext.Functions.Add(pFunc);
|
||||
sbMsg.AppendFormat("增加权限 {0}", parentName);
|
||||
}
|
||||
else
|
||||
{
|
||||
pzFunc.Sort = psort++;
|
||||
if (!string.IsNullOrWhiteSpace(parentNote) && pzFunc.Note != parentNote)
|
||||
{
|
||||
pzFunc.Note = parentNote;
|
||||
sbMsg.AppendFormat("备注改变 {0}:{1}", parentName, parentNote);
|
||||
}
|
||||
if (pzFunc.Type != type)
|
||||
{
|
||||
pzFunc.Type = type;
|
||||
sbMsg.AppendFormat("权限类型描述改变 {0}:{1}", parentName, type);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(title) && pzFunc.Title != title)
|
||||
{
|
||||
pzFunc.Title = title;
|
||||
sbMsg.AppendFormat("Title改变 {0}:{1}", parentName, title);
|
||||
}
|
||||
}
|
||||
|
||||
var childSort = 0;
|
||||
|
||||
foreach (XmlNode cnode in pxe.ChildNodes)
|
||||
{
|
||||
if (cnode.NodeType != XmlNodeType.Element || cnode.Name != "FunctionSub")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var cxe = (XmlElement)cnode;
|
||||
var cName = cxe.GetAttribute("Name").TrimToEmpty();
|
||||
var cNote = cxe.GetAttribute("Note").TrimToEmpty();
|
||||
var ctype = cxe.GetAttribute("Type").TrimToEmpty();
|
||||
var ctitle = cxe.GetAttribute("Title").TrimToEmpty();
|
||||
if (string.IsNullOrEmpty(cName))
|
||||
{
|
||||
throw new ServiceException("FunctionSub Name不能为空");
|
||||
}
|
||||
if (!funcDic.TryGetValue(parentName + "-" + cName, out var cFunc))
|
||||
{
|
||||
//没有节点
|
||||
var pFunc = new Function
|
||||
{
|
||||
Name = cName,
|
||||
Sort = childSort++,
|
||||
Note = cNote,
|
||||
ParentName = parentName,
|
||||
Type = ctype
|
||||
};
|
||||
DbContext.Functions.Add(pFunc);
|
||||
sbMsg.AppendFormat("增加子权限 {0}-{1}", parentName, cName);
|
||||
}
|
||||
else
|
||||
{
|
||||
cFunc.Sort = childSort++;
|
||||
if (!string.IsNullOrWhiteSpace(cNote) && cFunc.Note != cNote)
|
||||
{
|
||||
cFunc.Note = cNote;
|
||||
sbMsg.AppendFormat("备注改变 {0}:{1}", cName, cNote);
|
||||
}
|
||||
if (cFunc.Type != ctype)
|
||||
{
|
||||
cFunc.Type = ctype;
|
||||
sbMsg.AppendFormat("权限类型描述改变 {0}:{1}", cName, ctype);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(ctitle) && cFunc.Title != ctitle)
|
||||
{
|
||||
cFunc.Title = ctitle;
|
||||
sbMsg.AppendFormat("Title改变 {0}:{1}", cName, ctype);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DbContext.SaveChanges();
|
||||
|
||||
#region 从xml删除多余权限
|
||||
|
||||
foreach (var item in funcDic.Values)
|
||||
{
|
||||
if (item.Sort < 0)
|
||||
{
|
||||
DbContext.Functions.Remove(item);
|
||||
|
||||
if (item.ParentName.Replace("-", "").Trim() == "")
|
||||
{
|
||||
sbMsg.AppendFormat("删除权限 {0}", item.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
sbMsg.AppendFormat("删除子权限 {0}-{1}", item.ParentName, item.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DbContext.SaveChanges();
|
||||
|
||||
#endregion
|
||||
|
||||
sbMsg.AppendFormat("同步权限成功!");
|
||||
|
||||
return sbMsg.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
using BaseOUDAL;
|
||||
using System.Text;
|
||||
using YLErp.Providers;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统角色服务
|
||||
/// </summary>
|
||||
public class SysRoleService : BaseService<ErpBaseContext>
|
||||
{
|
||||
public SysRoleService(OptUserInfo optUser) : base(optUser)
|
||||
{
|
||||
}
|
||||
|
||||
public Role SaveRoleFunctions(RoleFunctionReq req)
|
||||
{
|
||||
if (DbContext.Roles.Any(role => role.Name == req.Name && role.Id != req.Id))
|
||||
{
|
||||
throw new ServiceException("已经存在相同的角色名称!");
|
||||
}
|
||||
|
||||
Role dbRole;
|
||||
|
||||
if (req.Id > 0)
|
||||
{
|
||||
dbRole = DbContext.Roles.FirstOrDefault(o => o.Id == req.Id);
|
||||
|
||||
if (dbRole == null)
|
||||
{
|
||||
throw new ServiceException("数据不存在!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbContext.Roles.Add(dbRole = new Role());
|
||||
}
|
||||
|
||||
dbRole.Name = req.Name;
|
||||
dbRole.Remark = req.Remark;
|
||||
dbRole.OptDate = DateTime.Now;
|
||||
|
||||
//角色创建以后才能配置权限
|
||||
if (req.Id > 0)
|
||||
{
|
||||
SetRoleFunc(req.Id, dbRole.Name, req.rights);
|
||||
}
|
||||
|
||||
DbContext.SaveChanges();
|
||||
|
||||
MemoryCacheProvider.Default.FlushAll();
|
||||
|
||||
return dbRole;
|
||||
}
|
||||
|
||||
private void SetRoleFunc(int roleId, string roleName, string rights)
|
||||
{
|
||||
var oldFuncIds = DbContext.RoleFunctions.Where(o => o.RoleId == roleId).Select(n => n.FunctionId).ToHashSet();
|
||||
|
||||
var newFuncIds = string.IsNullOrWhiteSpace(rights)
|
||||
? new HashSet<int>()
|
||||
: rights.Split(',').Select(n => int.TryParse(n, out var i) ? i : 0)
|
||||
.Distinct().Where(n => n > 0 && !oldFuncIds.Remove(n)).ToHashSet();
|
||||
|
||||
if (oldFuncIds.Count < 1 && newFuncIds.Count < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var allFunc = oldFuncIds.Concat(newFuncIds).ToArray();
|
||||
|
||||
var funcDic = allFunc.Any()
|
||||
? DbContext.Functions.Where(n => allFunc.Contains(n.Id)).ToDictionary(n => n.Id, m => m.Title ?? m.Name)
|
||||
: null;
|
||||
|
||||
//解除权限
|
||||
|
||||
var removeFuncList = new List<(int fid, string fname)>();
|
||||
|
||||
foreach (var fid in oldFuncIds)
|
||||
{
|
||||
var rf = DbContext.RoleFunctions.Attach(new RoleFunction { RoleId = roleId, FunctionId = fid }).Entity;
|
||||
|
||||
DbContext.RoleFunctions.Remove(rf);
|
||||
|
||||
var fname = funcDic != null && funcDic.TryGetValue(fid, out var str) ? str : null;
|
||||
|
||||
rf.SetDataTraceKeyInfo(roleName, fname);
|
||||
|
||||
if (fname != null)
|
||||
{
|
||||
removeFuncList.Add((fid, fname));
|
||||
}
|
||||
}
|
||||
|
||||
if (removeFuncList.Count < 1 && newFuncIds.Count < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//增加权限
|
||||
|
||||
var sbLog = new StringBuilder(300).Append("角色:").Append(roleName).Append(';');
|
||||
|
||||
if (removeFuncList.Count > 0)
|
||||
{
|
||||
sbLog.Append("解除权限:");
|
||||
foreach (var tuple in removeFuncList)
|
||||
{
|
||||
sbLog.Append(tuple.fname);
|
||||
}
|
||||
sbLog.Replace(',', ';', sbLog.Length - 1, 1);
|
||||
}
|
||||
|
||||
if (newFuncIds.Any())
|
||||
{
|
||||
sbLog.Append("增加权限:");
|
||||
|
||||
var newRoleFuncs = newFuncIds.Select(f =>
|
||||
{
|
||||
var rf = new RoleFunction { RoleId = roleId, FunctionId = f };
|
||||
var fname = funcDic != null && funcDic.TryGetValue(f, out var str) ? str : f.ToString();
|
||||
rf.SetDataTraceKeyInfo(roleName, fname);
|
||||
sbLog.Append(fname).Append(',');
|
||||
return rf;
|
||||
}).ToArray();
|
||||
|
||||
DbContext.RoleFunctions.AddRange(newRoleFuncs);
|
||||
|
||||
sbLog.Remove(sbLog.Length - 1, 1);
|
||||
}
|
||||
|
||||
DbContext.SystemLogs.Add(new DBModels.SystemLog
|
||||
{
|
||||
EventCategory = "角色权限",
|
||||
EventName = "设置权限",
|
||||
EventData = JsonHelper.Serialize(new
|
||||
{
|
||||
RoleId = roleId,
|
||||
NewFundIds = newFuncIds,
|
||||
RemoveFuncIds = removeFuncList.Select(n => n.fid).ToArray()
|
||||
}),
|
||||
Remark = sbLog.ToString()
|
||||
}).Entity.SetOpt(UserInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public class RoleFunctionReq
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Remark { get; set; }
|
||||
|
||||
public string rights { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace YLErp.Modules.SystemModule.SysToolModule.HeiXiang
|
||||
{
|
||||
/// <summary>
|
||||
/// 黑箱dailypnl验证
|
||||
/// </summary>
|
||||
public class HeixiangDailyPnlRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 波动率类型
|
||||
/// </summary>
|
||||
public string VolType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 黑箱主交易编号
|
||||
/// </summary>
|
||||
public string HxMainTradeNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结算日期
|
||||
/// </summary>
|
||||
public DateTime SettleDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace YLErp.Modules.SystemModule.SysToolModule.HeiXiang
|
||||
{
|
||||
/// <summary>
|
||||
/// 黑箱dailypnl验证
|
||||
/// </summary>
|
||||
public class HeixiangDailyPnlResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 交易编号
|
||||
/// </summary>
|
||||
public string TradeNumber { get; set; }
|
||||
/// <summary>
|
||||
/// 交易状态
|
||||
/// </summary>
|
||||
public string TradeStatus { get; set; }
|
||||
/// <summary>
|
||||
/// 上日持仓数量
|
||||
/// </summary>
|
||||
public string PrePositionNotional { get; set; }
|
||||
/// <summary>
|
||||
/// 当日持仓数量
|
||||
/// </summary>
|
||||
public string PositionNotional { get; set; }
|
||||
/// <summary>
|
||||
/// 上日PV
|
||||
/// </summary>
|
||||
public string PrePositionPv { get; set; }
|
||||
/// <summary>
|
||||
/// 当日PV
|
||||
/// </summary>
|
||||
public string PositionPv { get; set; }
|
||||
/// <summary>
|
||||
/// 当日盈亏
|
||||
/// </summary>
|
||||
public string PositionDailyPnl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// daily pnl calc
|
||||
/// </summary>
|
||||
public string DailyPnlCalc { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
using System.Text;
|
||||
using YLErp.Modules.CalculationModule;
|
||||
using YLErp.Modules.DataProviderModule;
|
||||
using YLErp.QdpModule;
|
||||
|
||||
namespace YLErp.Modules.SystemModule.SysToolModule.HeiXiang
|
||||
{
|
||||
/// <summary>
|
||||
/// 黑箱dailypnl验证
|
||||
/// </summary>
|
||||
public class HeixiangDailyPnlService : YLBaseService
|
||||
{
|
||||
public HeixiangDailyPnlService(OptUserInfo userInfo) : base(userInfo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取黑箱dailypnl验证数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<HeixiangDailyPnlResult> GetList(HeixiangDailyPnlRequest request)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.HxMainTradeNumber))
|
||||
{
|
||||
throw new ServiceException("黑箱主交易编号不能为空");
|
||||
}
|
||||
|
||||
var db = DbContextFactory.GetYLDbContext();
|
||||
|
||||
var preDate = QdpCalendarHelper.GetNonHolidayDefore(request.SettleDate.AddDays(-1));
|
||||
|
||||
var mainTrade = db.trade.Where(n => n.TradeNumber == request.HxMainTradeNumber)
|
||||
.Select(n => new { n.id }).FirstOrDefault();
|
||||
if (mainTrade == null)
|
||||
{
|
||||
throw new ServiceException("黑箱主交易 数据不存在");
|
||||
}
|
||||
|
||||
IQueryable<EodTradePosition> posQry = db.eod_trade_position;
|
||||
if (string.IsNullOrEmpty(request.VolType) || request.VolType == "对冲")
|
||||
{
|
||||
posQry = db.eod_trade_position_hedgevol;
|
||||
}
|
||||
|
||||
var query = from t in posQry
|
||||
join td in db.trade on t.TradeId equals td.id
|
||||
join pt in db.eod_trade_position.Where(n => n.ValueDate == preDate)
|
||||
on t.TradeId equals pt.TradeId into pt_s
|
||||
from pt in pt_s.DefaultIfEmpty()
|
||||
where t.ValueDate == request.SettleDate && t.ParentTradeId == mainTrade.id
|
||||
select new
|
||||
{
|
||||
td.TradeNumber,
|
||||
td.OriginalNotional,
|
||||
td.TradePrice,
|
||||
td.BuySell,
|
||||
td.OriginalPrincipalSum,
|
||||
t.TradeId,
|
||||
t.Amount,
|
||||
t.Pv,
|
||||
t.LastPv,
|
||||
t.ClosedPnL,
|
||||
t.DailyPnL,
|
||||
pre = pt == null ? null : new
|
||||
{
|
||||
pt.Pv,
|
||||
pt.Amount
|
||||
}
|
||||
};
|
||||
|
||||
var datas = query.ToArray();
|
||||
|
||||
var subTradeIds = datas.Select(n => n.TradeId).ToArray();
|
||||
var tcProvider = new TradeCashDataProvider();
|
||||
tcProvider.Initialize(subTradeIds);
|
||||
|
||||
var list = new List<HeixiangDailyPnlResult>(datas.Length + 1);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
double sumDailyPnl = 0d, sumDailyPnlCalc = 0d;
|
||||
|
||||
foreach (var item in datas)
|
||||
{
|
||||
var result = new HeixiangDailyPnlResult
|
||||
{
|
||||
TradeNumber = item.TradeNumber
|
||||
};
|
||||
|
||||
if (item.Amount < 1e-4)
|
||||
{
|
||||
result.TradeStatus = "完全了结";
|
||||
}
|
||||
else
|
||||
{
|
||||
var diff = Math.Abs((item.OriginalNotional ?? 0) - item.Amount);
|
||||
|
||||
if (diff < 1e-4)
|
||||
{
|
||||
result.TradeStatus = "全部成交";
|
||||
}
|
||||
else
|
||||
{
|
||||
result.TradeStatus = "部分了结";
|
||||
}
|
||||
}
|
||||
|
||||
double lastPv;
|
||||
|
||||
if (item.pre != null)
|
||||
{
|
||||
result.PrePositionPv = item.pre.Pv.OtcFormatFlex(2, 4);
|
||||
result.PrePositionNotional = item.pre.Amount.OtcFormatFlex(2, 4);
|
||||
lastPv = item.LastPv;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PS.Config.ErpElement.IsPVIncludePrincipal)
|
||||
{
|
||||
lastPv = item.TradePrice ?? 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastPv = (item.TradePrice ?? 0) - (item.OriginalPrincipalSum ?? 0);
|
||||
}
|
||||
if (item.BuySell == "卖出")
|
||||
{
|
||||
lastPv = -lastPv;
|
||||
}
|
||||
}
|
||||
|
||||
result.PositionPv = item.Pv.OtcFormatFlex(2, 4);
|
||||
result.PositionNotional = item.Amount.OtcFormatFlex(2, 4);
|
||||
result.PositionDailyPnl = item.DailyPnL.OtcFormatFlex(2, 4);
|
||||
|
||||
sb.Clear();
|
||||
sb.AppendFormat("pv({0}) - lastpv({1}) + 了结盈亏(", item.Pv.OtcFormatFlex(2, 4), lastPv.OtcFormatFlex(2, 4));
|
||||
|
||||
var dailyCalc = item.Pv - lastPv;
|
||||
|
||||
foreach (var c in tcProvider.GetTradeCashes(item.TradeId))
|
||||
{
|
||||
if (c.Action == ClientCashInCashOut.系统操作_期权费)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var unWindProfit = c.Amount;
|
||||
|
||||
if (!PS.Config.ErpElement.IsPVIncludePrincipal)
|
||||
{
|
||||
if (c.Action == ClientCashInCashOut.系统操作_行权费 || c.Action == ClientCashInCashOut.系统操作_平仓费 || c.IsLastAction)
|
||||
{
|
||||
unWindProfit -= (c.UnwindPercentRate ?? 0) * item.OriginalPrincipalSum.Value * TradeCalcHelper.GetSign(item.BuySell);
|
||||
}
|
||||
}
|
||||
|
||||
sb.Append(unWindProfit.OtcFormatFlex(2, 4)).Append(" + ");
|
||||
|
||||
dailyCalc += unWindProfit;
|
||||
}
|
||||
|
||||
if (sb[sb.Length - 2] == '+')
|
||||
{
|
||||
sb[sb.Length - 2] = ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(") ");
|
||||
}
|
||||
sb.Append(" = ").Append(dailyCalc.OtcFormatFlex(2, 4));
|
||||
|
||||
result.DailyPnlCalc = sb.ToString();
|
||||
|
||||
sumDailyPnl += item.DailyPnL;
|
||||
sumDailyPnlCalc += dailyCalc;
|
||||
|
||||
list.Add(result);
|
||||
}
|
||||
|
||||
var sumData = new HeixiangDailyPnlResult
|
||||
{
|
||||
TradeNumber = "合计:",
|
||||
PositionDailyPnl = sumDailyPnl.OtcFormatFlex(2, 4),
|
||||
DailyPnlCalc = sumDailyPnlCalc.OtcFormatFlex(2, 4)
|
||||
};
|
||||
|
||||
list.Add(sumData);
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using YLErp.Helpers;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统用户密码服务
|
||||
/// </summary>
|
||||
public class SysUserPasswordService : BaseService<BaseOUDAL.ErpBaseContext>
|
||||
{
|
||||
public SysUserPasswordService(OptUserInfo userInfo) : base(userInfo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 变更密码
|
||||
/// </summary>
|
||||
public void ChangePassword(UserChangePasswordRequest reqModel)
|
||||
{
|
||||
if (reqModel is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(reqModel));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(reqModel.Password))
|
||||
{
|
||||
throw new ServiceException("输入错误,缺少当前密码");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(reqModel.NewPassword))
|
||||
{
|
||||
throw new ServiceException("输入错误,缺少新密码");
|
||||
}
|
||||
|
||||
if (reqModel.NewPassword == null || reqModel.NewPassword.Length < 6 || !reqModel.NewPassword.Any(n => (n >= 'a' && n <= 'z') || (n >= 'A' && n <= 'Z')) || !reqModel.NewPassword.Any(n => n >= '0' && n <= '9'))
|
||||
{
|
||||
throw new ServiceException("密码长度至少6位并且包含英文字母和数字");
|
||||
}
|
||||
|
||||
var user = DbContext.SystemUsers.Where(u => u.Id == reqModel.UserId).FirstOrDefault();
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
throw new ServiceException("用户信息不存在");
|
||||
}
|
||||
|
||||
if (!DataHelper.EncryptPassword(user.LoginName.ToLowerInvariant(), reqModel.Password).Equals(user.Password, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new ServiceException("当前密码错误");
|
||||
}
|
||||
|
||||
user.Password = DataHelper.EncryptPassword(user.LoginName.ToLowerInvariant(), reqModel.NewPassword);
|
||||
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using BaseOUDAL;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
public class SysUserService : BaseService<BaseOUDAL.ErpBaseContext>
|
||||
{
|
||||
public SysUserService(OptUserInfo userInfo) : base(userInfo)
|
||||
{
|
||||
|
||||
}
|
||||
public void SaveSysUser(SystemUser user)
|
||||
{
|
||||
SysUser sysUser = DbContext.SysUsers.FirstOrDefault(x => x.id == user.Id);
|
||||
var add = false;
|
||||
if (sysUser == null)
|
||||
{
|
||||
sysUser = new SysUser();
|
||||
sysUser.id = user.Id;
|
||||
sysUser.create_time = DateTime.Now;
|
||||
sysUser.create_user = UserId;
|
||||
add = true;
|
||||
}
|
||||
sysUser.name = user.Name;
|
||||
sysUser.email = user.Email;
|
||||
sysUser.tel = user.Tel;
|
||||
sysUser.account = user.LoginName;
|
||||
sysUser.admin_type = 1;
|
||||
sysUser.phone = user.Mobile;
|
||||
if (!string.IsNullOrEmpty(user.Password))
|
||||
{
|
||||
sysUser.pwd_hash_value = user.Password;
|
||||
}
|
||||
sysUser.qq = user.QQ;
|
||||
sysUser.user_type = (byte)user.AccountPost;
|
||||
sysUser.status = (byte)user.State;
|
||||
sysUser.update_time = DateTime.Now;
|
||||
sysUser.update_user = UserId;
|
||||
sysUser.sex = 1;
|
||||
if (add)
|
||||
{
|
||||
DbContext.SysUsers.Add(sysUser);
|
||||
}
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
|
||||
public void RemoveSysUser(int id)
|
||||
{
|
||||
SysUser sysUser = DbContext.SysUsers.FirstOrDefault(x => x.id == id);
|
||||
if (sysUser!=null)
|
||||
{
|
||||
DbContext.SysUsers.Remove(sysUser);
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
public void UpdateState(int id,int state)
|
||||
{
|
||||
SysUser sysUser = DbContext.SysUsers.FirstOrDefault(x => x.id == id);
|
||||
if (sysUser != null)
|
||||
{
|
||||
sysUser.status = (byte)state;
|
||||
sysUser.update_time= DateTime.Now;
|
||||
sysUser.update_user = UserId;
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
using YLErp.Abstract;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统用户个性化配置服务
|
||||
/// </summary>
|
||||
public class SysUserConfigService : YLBaseService
|
||||
{
|
||||
public SysUserConfigService(OptUserInfo userInfo) : base(userInfo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SysUserConfigService(YLBaseService baseService) : base(baseService)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户个性化配置名称列表
|
||||
/// </summary>
|
||||
/// <param name="configType">配置类型</param>
|
||||
public Dictionary<SysUserConfigType, List<string>> GetConfigNames(bool useCommonTemplate = true)
|
||||
{
|
||||
var query = DbContext.SysUserConfig.AsNoTracking()
|
||||
.Where(n => (n.ConfigType == SysUserConfigType.PricingTemplateV2) && n.UserId == UserId);//获取个人模板
|
||||
if (useCommonTemplate)
|
||||
{
|
||||
query = query.Union(DbContext.SysUserConfig.AsNoTracking().Where(b => b.ConfigType == SysUserConfigType.CommonTemplate));//获取公共模板
|
||||
}
|
||||
query = query.OrderByDescending(n => n.UpdateTime);
|
||||
Dictionary<SysUserConfigType, List<string>> result = null;
|
||||
if (query.Any())
|
||||
{
|
||||
result = query.AsEnumerable().GroupBy(O => O.ConfigType).ToDictionary(K => K.Key, V => V.Select(O => O.ConfigName).ToList());
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new Dictionary<SysUserConfigType, List<string>>();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户个性化配置名称列表
|
||||
/// </summary>
|
||||
/// <param name="configType">配置类型</param>
|
||||
public List<SysUserConfigDto> GetConfigInfos(bool useCommonTemplate = true)
|
||||
{
|
||||
var sysUserConfigs = DbContext.SysUserConfig.AsNoTracking()
|
||||
.Where(n => (n.ConfigType == SysUserConfigType.PricingTemplateV2) && n.UserId == UserId);//获取个人模板
|
||||
if (useCommonTemplate)
|
||||
{
|
||||
sysUserConfigs = sysUserConfigs.Union(DbContext.SysUserConfig.AsNoTracking().Where(b => b.ConfigType == SysUserConfigType.CommonTemplate));//获取公共模板
|
||||
}
|
||||
sysUserConfigs = sysUserConfigs.OrderByDescending(n => n.UpdateTime);
|
||||
return sysUserConfigs.Any() ? sysUserConfigs.ProjectTo<SysUserConfigDto>().ToList() : new List<SysUserConfigDto>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户个性化配置名称列表
|
||||
/// </summary>
|
||||
/// <param name="configType">配置类型</param>
|
||||
public SysUserConfigDto GetConfigInfos(int id)
|
||||
{
|
||||
var sysUserConfigs = DbContext.SysUserConfig.AsNoTracking()
|
||||
.Where(n =>
|
||||
(n.ConfigType == SysUserConfigType.PricingTemplateV2
|
||||
&& n.UserId == UserId && n.id == id)
|
||||
|| (n.ConfigType == SysUserConfigType.CommonTemplate && n.id == id))
|
||||
.ProjectTo<SysUserConfigDto>();
|
||||
|
||||
return sysUserConfigs.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户个性化配置数据
|
||||
/// </summary>
|
||||
/// <param name="configType">配置类型</param>
|
||||
public Dictionary<string, string> GetConfigData(int userId, SysUserConfigType configType)
|
||||
{
|
||||
var datas = DbContext.SysUserConfig.Where(n => n.UserId == userId && n.ConfigType == configType).Select(n => new { n.ConfigName, n.ConfigData }).ToArray();
|
||||
|
||||
return datas.ToDictionary(n => n.ConfigName, m => m.ConfigData);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户个性化配置数据
|
||||
/// </summary>
|
||||
/// <param name="configType">配置类型</param>
|
||||
public Dictionary<string, string> GetConfigData(SysUserConfigType configType)
|
||||
{
|
||||
return GetConfigData(UserId, configType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户个性化配置数据
|
||||
/// </summary>
|
||||
/// <param name="configType">配置类型</param>
|
||||
/// <param name="configName">配置名称</param>
|
||||
public string GetConfigData(int userId, SysUserConfigType configType, string configName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(configName))
|
||||
{
|
||||
throw new ArgumentException("不能为空", nameof(configName));
|
||||
}
|
||||
if (configType == SysUserConfigType.CommonTemplate)
|
||||
{
|
||||
return DbContext.SysUserConfig.Where(n => n.ConfigType == configType && n.ConfigName == configName)
|
||||
.Select(n => n.ConfigData).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
return DbContext.SysUserConfig.Where(n => n.UserId == userId && n.ConfigType == configType && n.ConfigName == configName)
|
||||
.Select(n => n.ConfigData).FirstOrDefault();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户个性化配置数据
|
||||
/// </summary>
|
||||
/// <param name="configType">配置类型</param>
|
||||
/// <param name="configName">配置名称</param>
|
||||
public string GetConfigData(SysUserConfigType configType, string configName)
|
||||
{
|
||||
return GetConfigData(UserId, configType, configName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户个性化配置数据
|
||||
/// </summary>
|
||||
/// <param name="cacheProvider">缓存提供接口</param>
|
||||
public T GetConfigData<T>(int userId, ICacheProvider cacheProvider = null) where T : SysUserConfigModelBase, new()
|
||||
{
|
||||
var obj = new T();
|
||||
var configType = obj.GetConfigType();
|
||||
var configName = obj.GetConfigName();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(configName))
|
||||
{
|
||||
throw new ArgumentException("不能为空", nameof(configName));
|
||||
}
|
||||
|
||||
string cacheKey = null;
|
||||
|
||||
if (cacheProvider != null)
|
||||
{
|
||||
cacheKey = $"{configType}^{configName}^{userId}";
|
||||
if (cacheProvider.Get(cacheKey) is T userConfig)
|
||||
{
|
||||
return userConfig;
|
||||
}
|
||||
}
|
||||
|
||||
var configData = DbContext.SysUserConfig.Where(n => n.UserId == userId && n.ConfigType == configType && n.ConfigName == configName)
|
||||
.Select(n => n.ConfigData).FirstOrDefault();
|
||||
|
||||
var config = JsonHelper.Deserialize<T>(configData) ?? new T();
|
||||
|
||||
if (cacheProvider != null)
|
||||
{
|
||||
cacheProvider.Set(cacheKey, config, TimeSpan.FromMinutes(30));
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户个性化配置数据
|
||||
/// </summary>
|
||||
/// <param name="cacheProvider">缓存提供接口</param>
|
||||
public T GetConfigData<T>(ICacheProvider cacheProvider = null) where T : SysUserConfigModelBase, new()
|
||||
{
|
||||
return GetConfigData<T>(UserId, cacheProvider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存用户配置数据
|
||||
/// </summary>
|
||||
public SysUserConfig SaveData<T>(int userId, T config, ICacheProvider cacheProvider = null) where T : SysUserConfigModelBase
|
||||
{
|
||||
if (config is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(config));
|
||||
}
|
||||
|
||||
var configType = config.GetConfigType();
|
||||
var configName = config.GetConfigName();
|
||||
var configData = JsonHelper.Serialize(config);
|
||||
|
||||
return SaveData(userId, configType, configName, configData, cacheProvider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存用户配置数据
|
||||
/// </summary>
|
||||
public SysUserConfig SaveData<T>(T config, ICacheProvider cacheProvider = null) where T : SysUserConfigModelBase
|
||||
{
|
||||
return SaveData(UserId, config, cacheProvider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存用户配置数据
|
||||
/// </summary>
|
||||
/// <param name="configType">配置类型</param>
|
||||
/// <param name="configName">配置名词</param>
|
||||
/// <param name="configData">配置数据</param>
|
||||
/// <param name="cacheProvider">缓存接口</param>
|
||||
/// <param name="enableOverride">是否允许覆盖已有数据</param>
|
||||
/// <param name="enableCommtemplate">是否为公共模板/param>
|
||||
public SysUserConfig SaveData(int userId, SysUserConfigType configType, string configName, string configData, ICacheProvider cacheProvider = null, bool enableOverride = true, bool enableCommtemplate = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(configName))
|
||||
{
|
||||
throw new ArgumentException("不能为空", nameof(configName));
|
||||
}
|
||||
configType = enableCommtemplate ? SysUserConfigType.CommonTemplate : configType;//公共模板类型
|
||||
if (enableCommtemplate)
|
||||
{
|
||||
var dbmodel = DbContext.SysUserConfig.Where(n => n.ConfigType == configType && n.ConfigName == configName).FirstOrDefault();
|
||||
return SysUserConfigDataHandle(dbmodel, userId, configType, configName, configData, enableOverride, cacheProvider);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dbmodel = DbContext.SysUserConfig.Where(n => n.ConfigType == configType && n.ConfigName == configName && n.UserId == userId).FirstOrDefault();
|
||||
return SysUserConfigDataHandle(dbmodel, userId, configType, configName, configData, enableOverride, cacheProvider);
|
||||
}
|
||||
}
|
||||
|
||||
private SysUserConfig SysUserConfigDataHandle(SysUserConfig dbmodel, int userId, SysUserConfigType configType, string configName, string configData, bool enableOverride, ICacheProvider cacheProvider)
|
||||
{
|
||||
if (dbmodel == null)
|
||||
{
|
||||
dbmodel = new SysUserConfig
|
||||
{
|
||||
UserId = userId,//公共模板 SysUserConfigType.CommonTemplate
|
||||
ConfigType = configType,
|
||||
ConfigName = configName,
|
||||
CreateTime = DateTime.Now,
|
||||
};
|
||||
DbContext.SysUserConfig.Add(dbmodel);
|
||||
}
|
||||
else if (enableOverride)
|
||||
{
|
||||
dbmodel.UserId = userId;//公共模板 SysUserConfigType.CommonTemplate
|
||||
dbmodel.ConfigType = configType;
|
||||
dbmodel.ConfigName = configName;
|
||||
dbmodel.CreateTime = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ServiceException("不允许覆盖");
|
||||
}
|
||||
dbmodel.ConfigData = configData;
|
||||
dbmodel.UpdateTime = DateTime.Now;
|
||||
var changes = DbContext.SaveChanges();
|
||||
//设置缓存
|
||||
if (cacheProvider != null)
|
||||
{
|
||||
var cacheKey = $"{configType}^{configName}^{userId}";
|
||||
cacheProvider.Set(cacheKey, dbmodel, TimeSpan.FromMinutes(30));
|
||||
}
|
||||
return dbmodel;
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存当前用户配置数据
|
||||
/// </summary>
|
||||
/// <param name="configType">配置类型</param>
|
||||
/// <param name="configName">配置名词</param>
|
||||
/// <param name="configData">配置数据</param>
|
||||
/// <param name="cacheProvider">缓存接口</param>
|
||||
/// <param name="enableOverride">是否允许覆盖已有数据</param>
|
||||
public SysUserConfig SaveData(SysUserConfigType configType, string configName, string configData, ICacheProvider cacheProvider = null, bool enableOverride = true, bool enableCommtemplate = false)
|
||||
{
|
||||
return SaveData(UserId, configType, configName, configData, cacheProvider, enableOverride, enableCommtemplate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除配置数据
|
||||
/// </summary>
|
||||
public int RemoveData(int userId, SysUserConfigType configType, IEnumerable<string> configNames, ICacheProvider cacheProvider = null)
|
||||
{
|
||||
if (configNames == null || !configNames.Any(n => !string.IsNullOrEmpty(n)))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
configNames = configNames.Where(n => !string.IsNullOrEmpty(n)).ToArray();
|
||||
var dbmodels = DbContext.SysUserConfig.Where(n => n.UserId == userId && n.ConfigType == configType && configNames.Contains(n.ConfigName)).ToArray();
|
||||
DbContext.SysUserConfig.RemoveRange(dbmodels);
|
||||
var changes = DbContext.SaveChanges();
|
||||
|
||||
//设置缓存
|
||||
if (cacheProvider != null)
|
||||
{
|
||||
foreach (var name in configNames)
|
||||
{
|
||||
cacheProvider.Remove($"{configType}^{name}^{userId}");
|
||||
}
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
public int RemoveData(int sysUserConfigId, SysUserConfigType configType, ICacheProvider cacheProvider = null)
|
||||
{
|
||||
var sysUserConfig = DbContext.SysUserConfig.Where(a => a.id == sysUserConfigId).FirstOrDefault();
|
||||
if (sysUserConfig != null)
|
||||
{
|
||||
DbContext.SysUserConfig.Remove(sysUserConfig);
|
||||
|
||||
if (cacheProvider != null)
|
||||
{
|
||||
cacheProvider.Remove($"{configType}^{sysUserConfig.ConfigName}^{sysUserConfig.UserId}");
|
||||
}
|
||||
}
|
||||
var changes = DbContext.SaveChanges();
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除配置数据
|
||||
/// </summary>
|
||||
public int RemoveData(SysUserConfigType configType, IEnumerable<string> configNames, ICacheProvider cacheProvider = null)
|
||||
{
|
||||
return RemoveData(UserId, configType, configNames, cacheProvider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在用户配置数据
|
||||
/// </summary>
|
||||
public bool Exists(int userId, SysUserConfigType configType, string configName)
|
||||
{
|
||||
return DbContext.SysUserConfig.Any(n => n.UserId == userId && n.ConfigType == configType && n.ConfigName == configName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在用户配置数据
|
||||
/// </summary>
|
||||
public bool Exists(SysUserConfigType configType, string configName)
|
||||
{
|
||||
return Exists(UserId, configType, configName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在用户配置数据
|
||||
/// </summary>
|
||||
public bool Exists(int userId, SysUserConfigType configType, string configName, string configValue)
|
||||
{
|
||||
return DbContext.SysUserConfig.Any(n => n.UserId == userId && n.ConfigType == configType && n.ConfigName == configName && n.ConfigData == configValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在用户配置数据
|
||||
/// </summary>
|
||||
public bool Exists(SysUserConfigType configType, string configName, string configValue)
|
||||
{
|
||||
return Exists(UserId, configType, configName, configValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户个性化数据模型基类
|
||||
/// </summary>
|
||||
public abstract class SysUserConfigModelBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置类型(ConsConfigType)
|
||||
/// </summary>
|
||||
public abstract SysUserConfigType GetConfigType();
|
||||
|
||||
/// <summary>
|
||||
/// 配置名称
|
||||
/// </summary>
|
||||
public abstract string GetConfigName();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 风险对冲用户配置
|
||||
/// </summary>
|
||||
public class RiskHedgingUserConfig : SysUserConfigModelBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 场内期权现价使用行情价
|
||||
/// </summary>
|
||||
public bool UseMarketForExOptions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 显示时间戳
|
||||
/// </summary>
|
||||
public bool ShowTimestamp { get; set; }
|
||||
|
||||
public override string GetConfigName()
|
||||
{
|
||||
return "风险对冲";
|
||||
}
|
||||
|
||||
public override SysUserConfigType GetConfigType()
|
||||
{
|
||||
return SysUserConfigType.General;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OtcWeb用户配置
|
||||
/// </summary>
|
||||
public class OtcWebUserConfig : SysUserConfigModelBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 组合报价使用建议模式
|
||||
/// </summary>
|
||||
public bool Pricing_SimpleMode { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 组合报价是否计算预付金
|
||||
/// </summary>
|
||||
public bool Pricing_CalcMargin { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 组合报价是否计算凤凰/雪球期权风险值
|
||||
/// </summary>
|
||||
public bool Pricing_CalcAutocallGreeks { get; set; } = false;
|
||||
|
||||
public override string GetConfigName()
|
||||
{
|
||||
return "用户配置";
|
||||
}
|
||||
|
||||
public override SysUserConfigType GetConfigType()
|
||||
{
|
||||
return SysUserConfigType.General;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户更改密码请求数据
|
||||
/// </summary>
|
||||
public class UserChangePasswordRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前密码
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 新密码
|
||||
/// </summary>
|
||||
public string NewPassword { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user