159 lines
5.6 KiB
C#
159 lines
5.6 KiB
C#
using BaseOUDAL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using YLErp.DBModels;
|
|
|
|
namespace YLErp.Modules.SwapModule
|
|
{
|
|
public class SwapCapitalAccountService : YLBaseService
|
|
{
|
|
public SwapCapitalAccountService(OptUserInfo optUser) : base(optUser)
|
|
{
|
|
|
|
}
|
|
public SwapCapitalAccountService(YLBaseService baseService) : base(baseService)
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 查询资金账号
|
|
/// </summary>
|
|
public SearchListResult<swap_fund_account> SearchList(SwapCapitalAccountQueryRequest req)
|
|
{
|
|
var predicate = PredicateBuilder.Create<swap_fund_account>(n => 1==1);
|
|
if (req.ClientId>0)
|
|
{
|
|
predicate = predicate.And(n=>n.ClientId==req.ClientId);
|
|
}
|
|
if (!string.IsNullOrEmpty(req.TradeNumber))
|
|
{
|
|
predicate = predicate.And(n => n.SwapTradeNo.Contains(req.TradeNumber.Trim()));
|
|
}
|
|
if (!string.IsNullOrEmpty(req.FundAccount))
|
|
{
|
|
predicate = predicate.And(n => n.FundAccount.Contains(req.FundAccount.Trim()));
|
|
}
|
|
var query = DbContext.swap_fund_account.Where(predicate);
|
|
if (string.IsNullOrEmpty(req.sidx))
|
|
{
|
|
req.sidx = "id";
|
|
req.sord = "asc";
|
|
}
|
|
var retListResult = query.ToSearchList(req);
|
|
return retListResult;
|
|
}
|
|
/// <summary>
|
|
/// 保存资金账号
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
public void SaveCapitalAccount(swap_fund_account req)
|
|
{
|
|
CheckValid(req);
|
|
swap_fund_account capital = DbContext.swap_fund_account.Find(req.id);
|
|
if (capital==null)
|
|
{
|
|
capital = new swap_fund_account();
|
|
}
|
|
capital.SwapTradeNo = req.SwapTradeNo;
|
|
capital.SwapTradeId = req.SwapTradeId;
|
|
capital.Status = req.Status;
|
|
capital.ClientId = req.ClientId;
|
|
capital.ClientName = req.ClientName;
|
|
capital.FundAccount = req.FundAccount;
|
|
if (req.id == 0)
|
|
{
|
|
DbContext.swap_fund_account.Add(capital);
|
|
}
|
|
DbContext.SaveChanges();
|
|
}
|
|
/// <summary>
|
|
/// 删除场内资金账号
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <exception cref="ServiceException"></exception>
|
|
public void DeleteCapitalAccount(int id)
|
|
{
|
|
var capitalAccount= DbContext.swap_fund_account.Find(id);
|
|
if (capitalAccount==null)
|
|
{
|
|
throw new ServiceException("未找到该场内资金账号记录");
|
|
}
|
|
DbContext.swap_fund_account.Remove(capitalAccount);
|
|
DbContext.SaveChanges();
|
|
}
|
|
/// <summary>
|
|
/// 查看场内资金账号
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <exception cref="ServiceException"></exception>
|
|
public swap_fund_account GetCapitalAccount(int id)
|
|
{
|
|
var capitalAccount = DbContext.swap_fund_account.Find(id);
|
|
if (capitalAccount == null)
|
|
{
|
|
throw new ServiceException("未找到该场内资金账号记录");
|
|
}
|
|
return capitalAccount;
|
|
}
|
|
/// <summary>
|
|
/// 根据场内资金账号获取详情
|
|
/// </summary>
|
|
/// <param name="foundAccount"></param>
|
|
/// <returns></returns>
|
|
public swap_fund_account GetCapitalAccountByFoundAccount(string foundAccount)
|
|
{
|
|
return DbContext.swap_fund_account.FirstOrDefault(x=>x.FundAccount== foundAccount&&x.Status== (int)SwapFoundAccountStatusEnum.正常);
|
|
}
|
|
/// <summary>
|
|
/// 必填项校验
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <exception cref="ServiceException"></exception>
|
|
private void CheckRequired(swap_fund_account req)
|
|
{
|
|
if (req.ClientId == 0)
|
|
{
|
|
throw new ServiceException("交易对手方不能为空");
|
|
}
|
|
if (req.SwapTradeId == 0)
|
|
{
|
|
throw new ServiceException("互换编码不能为空");
|
|
}
|
|
if (string.IsNullOrEmpty(req.FundAccount)&&string.IsNullOrEmpty(req.FundAccount.Trim()))
|
|
{
|
|
throw new ServiceException("资金账号不能为空");
|
|
}
|
|
req.FundAccount=req.FundAccount.Trim();
|
|
//var uPattern = "^[0 - 9]{ 6,20}$";
|
|
//Regex regex = new Regex(uPattern);
|
|
//if (regex.IsMatch(req.FundAccount))
|
|
//{
|
|
// throw new ServiceException("资金账号应为20位以内的数字");
|
|
//}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数据有效性校验
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
private void CheckValid(swap_fund_account req)
|
|
{
|
|
CheckRequired(req);
|
|
var predicate = PredicateBuilder.Create<swap_fund_account>(n => n.FundAccount == req.FundAccount&&n.Status== (int)SwapFoundAccountStatusEnum.正常);
|
|
if (req.id > 0)
|
|
{
|
|
predicate = predicate.And(n => n.id != req.id);
|
|
}
|
|
if (DbContext.swap_fund_account.Any(predicate))
|
|
{
|
|
throw new ServiceException("已经存在正常状态的资金账号");
|
|
}
|
|
}
|
|
}
|
|
}
|